For Spring Boot 1.2.3, how to set ignore null value in JSON serialization?

前端 未结 6 1953

In the Spring Boot 1.2.3, we can customize the Jackson ObjectMapper via properties file. But I didn\'t find a attribute can set Jackson ignore null value when serialization

6条回答
  •  [愿得一人]
    2020-12-18 18:57

    Class-wide,

    @JsonInclude(JsonInclude.Include.NON_NULL)
    public class MyModel { .... }
    

    Property-wide:

    public class MyModel {   
        .....
    
        @JsonInclude(JsonInclude.Include.NON_NULL)
        private String myProperty;
    
        .....
    }
    

提交回复
热议问题