Skip to content

Revisit Jackson support #33798

Closed
Closed
@sdeleuze

Description

@sdeleuze

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:

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 using com.fasterxml.jackson
  • ObjectMapper#canDeserialize and ObjectMapper#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, impact ProblemDetail)
  • Jackson 3 defaults are aligned with Spring ones:
    • MapperFeature.DEFAULT_VIEW_INCLUSION is disabled by default
    • DeserializationFeature.FAIL_ON_UNEXPECTED_VIEW_PROPERTIES is disabled by default

General:

  • No Jackson 3 equivalent of Jackson2ObjectMapperBuilder is provided, the recommendation is to use JsonMapper.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 to SmartHttpMessageConverter which support hints
  • Use hints instead of MappingJacksonValue and MappingJacksonInputMessage to support @JsonView and FilterProvider
  • Introduction of RequestBodyAdvice#determineReadHints and ResponseBodyAdvice#determineWriteHints
  • JsonViewRequestBodyAdvice and JsonViewResponseBodyAdvice 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:

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)in: webIssues in web modules (web, webmvc, webflux, websocket)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions