How to tell Jackson to ignore a field during serialization if its value is null?

后端 未结 19 1215
情歌与酒
情歌与酒 2020-11-22 04:55

How can Jackson be configured to ignore a field value during serialization if that field\'s value is null.

For example:

public class SomeClass {
            


        
19条回答
  •  后悔当初
    2020-11-22 05:11

    Case one

    @JsonInclude(JsonInclude.Include.NON_NULL)
    private String someString;
    

    Case two

    @JsonInclude(JsonInclude.Include.NON_EMPTY)
    private String someString;
    

    If someString is null, it will be ignored on both of cases. If someString is "" it just only be ignored on case two.

    The same for List = null or List.size() = 0

提交回复
热议问题