Spring Boot:自定义Jackson ObjectMapper_spring.jackson.default-property-inclusion-CSDN博客

Spring Boot JSON — Jackson

Customize the Jackson ObjectMapper

*https://docs.spring.io/spring-boot/docs/2.7.17/reference/htmlsingle/*

Spring MVC (client and server side) uses HttpMessageConverters to negotiate content conversion in an HTTP exchange. If Jackson is on the classpath, you already get the default converter(s) provided by Jackson2ObjectMapperBuilder, an instance of which is auto-configured for you.

The ObjectMapper (or XmlMapper for Jackson XML converter) instance (created by default) has the following customized properties:

Spring Boot also has some features to make it easier to customize this behavior.

You can configure the ObjectMapper and XmlMapper instances by using the environment. Jackson provides an extensive suite of on/off features that can be used to configure various aspects of its processing. These features are described in six enums (in Jackson) that map onto properties in the environment:

Enum Property Values
com.fasterxml.jackson.databind.DeserializationFeature spring.jackson.deserialization.<feature_name> truefalse
com.fasterxml.jackson.core.JsonGenerator.Feature spring.jackson.generator.<feature_name> truefalse
com.fasterxml.jackson.databind.MapperFeature spring.jackson.mapper.<feature_name> truefalse
com.fasterxml.jackson.core.JsonParser.Feature spring.jackson.parser.<feature_name> truefalse
com.fasterxml.jackson.databind.SerializationFeature spring.jackson.serialization.<feature_name> truefalse
com.fasterxml.jackson.annotation.JsonInclude.Include spring.jackson.default-property-inclusion alwaysnon_nullnon_absentnon_defaultnon_empty