SpringMVC @JsonDeserialize doesn't work

2019-07-21 10:28发布

问题:

I got a very simple POJO like below:

@Entity
@Table(name = "people")
public class People(){

   @Id
   @GeneratedValue(strategy = GenerationType.IDENTITY)
   private Integer peopleId;

   private Date birthday;

   @JsonDeserialize(using = DateDeserializer.class)
   public void setBirthday(Date birthday){
     this.birthday = birthday;
   }
}

DateDeserializer:

public class DateDeserializer extends JsonDeserializer<Date> {

    @Override
    public Date deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
        System.out.print("abc2222222222222222222222222222");
        return new Date();
    }
}

However this deserializer never be invoked at all, I tested @JSonSerializer which works perfectly. is there anything I did wrongly or missed something?