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

后端 未结 19 1153
情歌与酒
情歌与酒 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:26

    If in Spring Boot, you can customize the jackson ObjectMapper directly through property files.

    Example application.yml:

    spring:
      jackson:
        default-property-inclusion: non_null # only include props if non-null
    

    Possible values are:

    always|non_null|non_absent|non_default|non_empty
    

    More: https://docs.spring.io/spring-boot/docs/current/reference/html/howto-spring-mvc.html#howto-customize-the-jackson-objectmapper

提交回复
热议问题