Spring Boot:自定义Jackson ObjectMapper_spring.jackson.default-property-inclusion-CSDN博客
*https://docs.spring.io/spring-boot/docs/2.7.17/reference/htmlsingle/*
Spring MVC (client and server side) uses
HttpMessageConvertersto negotiate content conversion in an HTTP exchange. If Jackson is on the classpath, you already get the default converter(s) provided byJackson2ObjectMapperBuilder, an instance of which is auto-configured for you.The
ObjectMapper(orXmlMapperfor Jackson XML converter) instance (created by default) has the following customized properties:
MapperFeature.DEFAULT_VIEW_INCLUSIONis disabledDeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIESis disabledSerializationFeature.WRITE_DATES_AS_TIMESTAMPSis disabledSpring Boot also has some features to make it easier to customize this behavior.
You can configure the
ObjectMapperandXmlMapperinstances 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.DeserializationFeaturespring.jackson.deserialization.<feature_name>true,falsecom.fasterxml.jackson.core.JsonGenerator.Featurespring.jackson.generator.<feature_name>true,falsecom.fasterxml.jackson.databind.MapperFeaturespring.jackson.mapper.<feature_name>true,falsecom.fasterxml.jackson.core.JsonParser.Featurespring.jackson.parser.<feature_name>true,falsecom.fasterxml.jackson.databind.SerializationFeaturespring.jackson.serialization.<feature_name>true,falsecom.fasterxml.jackson.annotation.JsonInclude.Includespring.jackson.default-property-inclusionalways,non_null,non_absent,non_default,non_empty