How right to build JACKSON DeserializationConfig to work on Date



  • How to build Jackson. DeserializationConfig so he wouldn't be in the field of the target date? This is the situation. I come. DateGETand if one of the parameters is empty, then Jackson will disfigure it on the date that is now.

    I need a parameter with a date not filled, it was NULL.



  • You probably have a field of initiation somewhere in the bin itself. Or Jackson's old 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]




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2