How to configure Jackson DeserializationConfig so that he would not put in the fields of the date object? Now the situation is this. Date comes to me via GET , and if any of the parameters is empty, then Jackson disrealizes it to the date, which is now.

I need that if the parameter with the date is not filled, then it was NULL.

  • add to the question an example of a date giving an incorrect result - zRrr

1 answer 1

You, probably, somewhere in the bin itself, the field is initialized. Or the old Jackson version.

 public class Bean { public String name; public Date date; @Override public String toString() { return "Bean [name=" + name + ", date=" + date + "]"; } } String json0 = "{ \"name\": \"test\" }"; String json1 = "{ \"name\": \"test\", \"date\": \"\" }"; String json2 = "{ \"name\": \"test\", \"date\": \"null\" }"; String json3 = "{ \"name\": \"test\", \"date\": \"2016-06-11\" }"; ObjectMapper mapper = new ObjectMapper(); System.out.println(mapper.readValue(json0, Bean.class)); // Bean [name=test, date=null] System.out.println(mapper.readValue(json1, Bean.class)); // Bean [name=test, date=null] System.out.println(mapper.readValue(json2, Bean.class)); // Bean [name=test, date=null] System.out.println(mapper.readValue(json3, Bean.class)); // Bean [name=test, date=Sat Jun 11 00:00:00 TZ 2016] 
  • Problem was not in jackson - Stanislav Dushkin