Closed
Description
Spring Framework 7.0 introduces Jackson 3 support in parallel of the now deprecated Jackson 2 one.
More information can be found on the changes of migrating from Jackson 2 to Jackson 3 in the following links:
- Taking Jackson 3.0.0-rc1 for a spin
- Jackson 3.0.0-rc2 (minor update)
- Jackson 3.0.0-rc3
- Jackson 3.0.0-rc4
- Path to Jackson 3.0.0
The Jackson 3 changes with the biggest impact on Spring use-cases are:
- Jackson 3 uses a different package (
tools.jackson
) than Jackson 2 (com.fasterxml.jackson
) except for jackson-annotation (@JsonView
,@JsonTypeInfo
) which keeps usingcom.fasterxml.jackson
ObjectMapper#canDeserialize
andObjectMapper#canSerialize
have been removed as they were not reliable, so Jackson 3 converters and codecs only test mime types and type resolution in their canXxx methods.- The order of properties is now alphabetical by default (can be changed with
MapperFeature.SORT_PROPERTIES_ALPHABETICALLY
) - Slashes are now escaped by default (can be changed with
JsonWriteFeature.ESCAPE_FORWARD_SLASHES
, impactProblemDetail
) - Jackson 3 defaults are aligned with Spring ones:
MapperFeature.DEFAULT_VIEW_INCLUSION
is disabled by defaultDeserializationFeature.FAIL_ON_UNEXPECTED_VIEW_PROPERTIES
is disabled by default
General:
- No Jackson 3 equivalent of
Jackson2ObjectMapperBuilder
is provided, the recommendation is to useJsonMapper.builder()
,CBORMapper.builder()
, etc. - By default, Jackson modules discovered by
MapperBuilder#findModules(java.lang.ClassLoader)
are registered in converters and codecs org.springframework.http.converter.json.SpringHandlerInstantiator
enabled by default in Spring MVC ->
org.springframework.http.support.JacksonHandlerInstantiator
now requires explicit configuration- Jackson 3 support is configured if found in the classpath otherwise fallback to Jackson 2
- Jackson 2 support will be deprecated for removal (current plan is autodetection disabled in 7.1, and removal done in 7.2)
WebMVC:
- Switch from
GenericHttpMessageConverter
toSmartHttpMessageConverter
which support hints - Use hints instead of
MappingJacksonValue
andMappingJacksonInputMessage
to support@JsonView
andFilterProvider
- Introduction of
RequestBodyAdvice#determineReadHints
andResponseBodyAdvice#determineWriteHints
JsonViewRequestBodyAdvice
andJsonViewResponseBodyAdvice
supports both Jackson 2 (with wrappers) and Jackson 3 (with hints)org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter
->org.springframework.http.converter.AbstractJacksonHttpMessageConverter
MappingJackson2HttpMessageConverter
->JacksonJsonHttpMessageConverter
MappingJackson2SmileHttpMessageConverter
->JacksonSmileHttpMessageConverter
MappingJackson2CborHttpMessageConverter
->JacksonCborHttpMessageConverter
MappingJackson2XmlHttpMessageConverter
->JacksonXmlHttpMessageConverter
MappingJackson2YamlHttpMessageConverter
->JacksonYamlHttpMessageConverter
MappingJackson2JsonView
->JacksonJsonView
MappingJackson2XmlView
->JacksonXmlView
WebFlux:
org.springframework.http.codec.json.Jackson2CodecSupport
->org.springframework.http.codec.JacksonCodecSupport
org.springframework.http.codec.json.Jackson2Tokenizer
->org.springframework.http.codec.JacksonTokenizer
org.springframework.http.codec.json.Jackson2SmileDecoder
->org.springframework.http.codec.smile.JacksonSmileDecoder
org.springframework.http.codec.json.Jackson2SmileEncoder
->org.springframework.http.codec.smile.JacksonSmileEncoder
Jackson2CborDecoder
->JacksonCborDecoder
Jackson2CborEncoder
->JacksonCborEncoder
Jackson2JsonDecoder
->JacksonJsonDecoder
Jackson2JsonEncoder
->JacksonJsonEncoder
Messaging:
MappingJackson2MessageConverter
->JacksonJsonMessageConverter
JMS:
MappingJackson2MessageConverter
->JacksonJsonMessageConverter
TODO:
- Fix RFC 9457 XML support via
@JacksonXmlRootElement
is ignored with Jackson 3 FasterXML/jackson-dataformat-xml#757 - Add support for hints in
RestClient
to support@JsonView
andFilterProvider
(no support inRestTemplate
, migration path will be to switch toRestClient
) - Update the reference documentation