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

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

    You can set application.properties:

    spring.jackson.default-property-inclusion=non_null
    

    or application.yaml:

    spring:
      jackson:
        default-property-inclusion: non_null
    

    http://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.html

    0 讨论(0)
提交回复
热议问题