How to deserialize a blank JSON string value to null for java.lang.String?

前端 未结 6 1445
既然无缘
既然无缘 2020-12-01 16:10

I am trying a simple JSON to de-serialize in to java object. I am however, getting empty String values for java.lang.String property values. In rest of

6条回答
  •  半阙折子戏
    2020-12-01 16:35

    it is possible to use JsonCreator annotation. It worked for me

    public class Foo {
    private String field;
    
     @JsonCreator
     public Foo(
       @JsonProrerty("field") String field) {
         this.field = StringUtils.EMPTY.equals(field) ? null : field ;
    }
    }
    

提交回复
热议问题