Skip to content

Revisit Jackson support #33798

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
sdeleuze opened this issue Oct 25, 2024 · 2 comments
Closed

Revisit Jackson support #33798

sdeleuze opened this issue Oct 25, 2024 · 2 comments
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Milestone

Comments

@sdeleuze
Copy link
Contributor

sdeleuze commented Oct 25, 2024

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:

@sdeleuze sdeleuze added in: web Issues in web modules (web, webmvc, webflux, websocket) in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement labels Oct 25, 2024
@sdeleuze sdeleuze added this to the 7.0.x milestone Oct 25, 2024
@sdeleuze sdeleuze self-assigned this Oct 25, 2024
@sdeleuze sdeleuze modified the milestones: 7.0.x, 7.0.0-M4 Mar 17, 2025
@sdeleuze
Copy link
Contributor Author

See the related blog post https://cowtowncoder.medium.com/taking-jackson-3-0-0-rc1-for-a-spin-17282161a6b2.

@sdeleuze
Copy link
Contributor Author

sdeleuze added a commit to sdeleuze/spring-framework that referenced this issue May 13, 2025
This commit adds Jackson 3 BOM to Spring Framework platform dependencies
and related Javadoc link.

See spring-projectsgh-33798
sdeleuze added a commit to sdeleuze/spring-framework that referenced this issue May 13, 2025
This commit introduces Jackson 3 variants of the following Jackson 2
classes (and related dependent classes).

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

Jackson 3 support is configured if found in the classpath otherwise
fallback to Jackson 2.

See spring-projectsgh-33798
sdeleuze added a commit to sdeleuze/spring-framework that referenced this issue May 13, 2025
This commit introduces a
org.springframework.http.support.JacksonHandlerInstantiator Jackson 3
variant of org.springframework.http.converter.json.SpringHandlerInstantiator
Jackson 2 class.

See spring-projectsgh-33798
sdeleuze added a commit to sdeleuze/spring-framework that referenced this issue May 13, 2025
This commit introduces Jackson 3 GenericHttpMessageConverter based
variants of the following Jackson 2 classes (and related dependent classes).

org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter ->
org.springframework.http.converter.AbstractJacksonHttpMessageConverter

MappingJackson2HttpMessageConverter -> JacksonJsonHttpMessageConverter
MappingJackson2SmileHttpMessageConverter -> JacksonSmileHttpMessageConverter
MappingJackson2CborHttpMessageConverter -> JacksonCborHttpMessageConverter
MappingJackson2XmlHttpMessageConverter -> JacksonXmlHttpMessageConverter
MappingJackson2YamlHttpMessageConverter -> JacksonYamlHttpMessageConverter

They use hints instead of MappingJacksonValue and MappingJacksonInputMessage
to support `@JsonView` and FilterProvider.

Jackson 3 support is configured if found in the classpath otherwise
fallback to Jackson 2.

See spring-projectsgh-33798
sdeleuze added a commit to sdeleuze/spring-framework that referenced this issue May 13, 2025
This commit introduces Jackson 3 based variants of the following
Jackson 2 classes (and related dependent classes).

MappingJackson2JsonView -> JacksonJsonView
MappingJackson2XmlView-> JacksonXmlView

See spring-projectsgh-33798
sdeleuze added a commit to sdeleuze/spring-framework that referenced this issue May 13, 2025
This commit introduces RequestBodyAdvice#determineReadHints and
ResponseBodyAdvice#determineWriteHints in order to be able to support
SmartHttpMessageConverter hints, as well as related `@JsonView`
support.

See spring-projectsgh-33798
sdeleuze added a commit to sdeleuze/spring-framework that referenced this issue May 13, 2025
This commit introduces a JacksonJsonMessageConverter Jackson 3 variant
of MappingJackson2MessageConverter.

See spring-projectsgh-33798
sdeleuze added a commit to sdeleuze/spring-framework that referenced this issue May 13, 2025
This commit introduces a JacksonJsonMessageConverter Jackson 3 variant
of MappingJackson2MessageConverter.

See spring-projectsgh-33798
sdeleuze added a commit to sdeleuze/spring-framework that referenced this issue May 13, 2025
This commit introduces a JacksonJsonSockJsMessageCodec Jackson 3 variant
of Jackson2SockJsMessageCodec.

See spring-projectsgh-33798
sdeleuze added a commit to sdeleuze/spring-framework that referenced this issue May 13, 2025
sdeleuze added a commit to sdeleuze/spring-framework that referenced this issue May 13, 2025
sdeleuze added a commit to sdeleuze/spring-framework that referenced this issue May 13, 2025
This commit adds Jackson 3 BOM to Spring Framework platform dependencies
and related Javadoc link.

See spring-projectsgh-33798
sdeleuze added a commit to sdeleuze/spring-framework that referenced this issue May 13, 2025
This commit introduces Jackson 3 variants of the following Jackson 2
classes (and related dependent classes).

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

Jackson 3 support is configured if found in the classpath otherwise
fallback to Jackson 2.

See spring-projectsgh-33798
sdeleuze added a commit to sdeleuze/spring-framework that referenced this issue May 13, 2025
This commit introduces a
org.springframework.http.support.JacksonHandlerInstantiator Jackson 3
variant of org.springframework.http.converter.json.SpringHandlerInstantiator
Jackson 2 class.

See spring-projectsgh-33798
sdeleuze added a commit to sdeleuze/spring-framework that referenced this issue May 13, 2025
This commit introduces Jackson 3 SmartHttpMessageConverter based
variants of the following Jackson 2 classes (and related dependent classes).

org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter ->
org.springframework.http.converter.AbstractJacksonHttpMessageConverter

MappingJackson2HttpMessageConverter -> JacksonJsonHttpMessageConverter
MappingJackson2SmileHttpMessageConverter -> JacksonSmileHttpMessageConverter
MappingJackson2CborHttpMessageConverter -> JacksonCborHttpMessageConverter
MappingJackson2XmlHttpMessageConverter -> JacksonXmlHttpMessageConverter
MappingJackson2YamlHttpMessageConverter -> JacksonYamlHttpMessageConverter

They use hints instead of MappingJacksonValue and MappingJacksonInputMessage
to support `@JsonView` and FilterProvider.

Jackson 3 support is configured if found in the classpath otherwise
fallback to Jackson 2.

JacksonHandlerInstantiator needs to be enabled explicitly if needed.

See spring-projectsgh-33798
sdeleuze added a commit to sdeleuze/spring-framework that referenced this issue May 13, 2025
This commit introduces Jackson 3 based variants of the following
Jackson 2 classes (and related dependent classes).

MappingJackson2JsonView -> JacksonJsonView
MappingJackson2XmlView-> JacksonXmlView

See spring-projectsgh-33798
sdeleuze added a commit to sdeleuze/spring-framework that referenced this issue May 13, 2025
This commit introduces RequestBodyAdvice#determineReadHints and
ResponseBodyAdvice#determineWriteHints in order to be able to support
SmartHttpMessageConverter hints, as well as related `@JsonView`
support.

See spring-projectsgh-33798
sdeleuze added a commit to sdeleuze/spring-framework that referenced this issue May 13, 2025
This commit introduces a JacksonJsonMessageConverter Jackson 3 variant
of MappingJackson2MessageConverter.

See spring-projectsgh-33798
sdeleuze added a commit to sdeleuze/spring-framework that referenced this issue May 13, 2025
This commit introduces a JacksonJsonMessageConverter Jackson 3 variant
of MappingJackson2MessageConverter.

See spring-projectsgh-33798
sdeleuze added a commit to sdeleuze/spring-framework that referenced this issue May 13, 2025
This commit introduces a JacksonJsonSockJsMessageCodec Jackson 3 variant
of Jackson2SockJsMessageCodec.

See spring-projectsgh-33798
sdeleuze added a commit to sdeleuze/spring-framework that referenced this issue May 13, 2025
sdeleuze added a commit to sdeleuze/spring-framework that referenced this issue May 13, 2025
sdeleuze added a commit to sdeleuze/spring-framework that referenced this issue May 13, 2025
sdeleuze added a commit to sdeleuze/spring-framework that referenced this issue May 13, 2025
This commit deprecate for removal (likely in a future 7.x release) the
Jackson 2 support in favor of the Jackson 3 one.

Closes spring-projectsgh-33798
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

1 participant