Skip to content

Conversation

@sdeleuze
Copy link
Contributor

@sdeleuze sdeleuze commented Sep 1, 2025

This PR adds support for Jackson 3 which has the following major differences with the Jackson 2 one:

  • jackson subpackage instead of jackson2
  • Jackson type prefix instead of Jackson2
  • JsonMapper instead of ObjectMapper
  • For configuration, JsonMapper.Builder instead of ObjectMapper since the latter is now immutable
  • AllowlistTypeResolverBuilder in new a public type in order to be used easily with the JsonMapper.Builder API

Jackson 3 changes compared to Jackson 2 are documented on FasterXML/jackson-future-ideas#72.

It also deprecates Jackson 2 support for removal.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Sep 1, 2025
Copy link
Member

@rwinch rwinch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the pull request. Generally, I think this is looking good. I've provided some feedback inline.

It also appears that there are still some classes that need migrated. Searching for jackson on main should give you a complete list of classes that are using jackson.

For example, webauthn has jackson support. I'm guessing this was missed because it is inconsistent with the rest of the jackson support in that it is in a jackson package rather than jackson2. It is also automatically registered because it does not use default types which would make it insecure.

There are also some tests that still use ObjectMapper or deprecated Spring Framework Jackson 2 classes (e.g. JwtDecodersTests.java#L388). Unless the test is specifically for the Jackson 2 support, we should update these to use non-deprecated classes (e.g. JsonMapper).

There are various Spring framework jackson based classes that have been deprecated that we should migrate away from. For example, MappingJackson2HttpMessageConverter usage (e.g. WebAuthnAuthenticationFilter.converter) should be migrated to JacksonJsonHttpMessageConverter if jackson 3 is on the classpath. Likely there could be a static factory method used that Spring Security uses to obtain the correct default json converter instance.

@sdeleuze
Copy link
Contributor Author

sdeleuze commented Sep 8, 2025

@rwinch I have pushed additional commits:

I will do another pass with your feedback to my questions in the comments.

@sdeleuze sdeleuze force-pushed the jackson3 branch 2 times, most recently from e7d5c41 to 20a69ea Compare September 10, 2025 21:06
sdeleuze added a commit to sdeleuze/spring-security that referenced this pull request Sep 10, 2025
See spring-projectsgh-17832
Signed-off-by: Sébastien Deleuze <[email protected]>
sdeleuze added a commit to sdeleuze/spring-security that referenced this pull request Sep 10, 2025
This commit adds support for Jackson 3 which has the following
major differences with the Jackson 2 one:
 - jackson subpackage instead of jackson2
 - Jackson type prefix instead of Jackson2
 - JsonMapper instead of ObjectMapper
 - For configuration, JsonMapper.Builder instead of ObjectMapper
   since the latter is now immutable
 - Remove custom Jackson 3 support for unmodifiable collections
 - AllowlistTypeResolverBuilder in new a public type in order
   to be used easily with the JsonMapper.Builder API

Jackson 3 changes compared to Jackson 2 are documented on
FasterXML/jackson-future-ideas#72.

This commit does not cover webauthn which is a special case (uses
jackson sub-package for Jackson 2 support) which will be handled in
a distinct commit.

See spring-projectsgh-17832
Signed-off-by: Sébastien Deleuze <[email protected]>
sdeleuze added a commit to sdeleuze/spring-security that referenced this pull request Sep 10, 2025
This commit does not cover webauthn which is a special case (uses
jackson sub-package for Jackson 2 support) which will be handled in
a distinct commit.

See spring-projectsgh-17832
Signed-off-by: Sébastien Deleuze <[email protected]>
sdeleuze added a commit to sdeleuze/spring-security that referenced this pull request Sep 10, 2025
Since this module was already using the jackson sub-package for Jackson 2
support, both Jackson 2 and Jackson 3 support lives in the same subpackage
and the former package-private classes has been renamed with a Jackson2
qualifier.

Closes spring-projectsgh-17832
Signed-off-by: Sébastien Deleuze <[email protected]>
@sdeleuze
Copy link
Contributor Author

@rwinch I have removed the custom support for unmodifiable collections (seems to work fine with Jackson 3), reworked the commit for a cleaner git history, and rebased the commits on main.

This was referenced May 14, 2025
sdeleuze added a commit to sdeleuze/spring-security that referenced this pull request Sep 25, 2025
See spring-projectsgh-17832
Signed-off-by: Sébastien Deleuze <[email protected]>
sdeleuze added a commit to sdeleuze/spring-security that referenced this pull request Sep 25, 2025
This commit adds support for Jackson 3 which has the following
major differences with the Jackson 2 one:
 - jackson subpackage instead of jackson2
 - Jackson type prefix instead of Jackson2
 - JsonMapper instead of ObjectMapper
 - For configuration, JsonMapper.Builder instead of ObjectMapper
   since the latter is now immutable
 - Remove custom Jackson 3 support for unmodifiable collections
 - AllowlistTypeResolverBuilder in new a public type in order
   to be used easily with the JsonMapper.Builder API

Jackson 3 changes compared to Jackson 2 are documented on
FasterXML/jackson-future-ideas#72.

This commit does not cover webauthn which is a special case (uses
jackson sub-package for Jackson 2 support) which will be handled in
a distinct commit.

See spring-projectsgh-17832
Signed-off-by: Sébastien Deleuze <[email protected]>
sdeleuze added a commit to sdeleuze/spring-security that referenced this pull request Sep 25, 2025
This commit does not cover webauthn which is a special case (uses
jackson sub-package for Jackson 2 support) which will be handled in
a distinct commit.

See spring-projectsgh-17832
Signed-off-by: Sébastien Deleuze <[email protected]>
sdeleuze added a commit to sdeleuze/spring-security that referenced this pull request Sep 25, 2025
Since this module was already using the jackson sub-package for Jackson 2
support, both Jackson 2 and Jackson 3 support lives in the same subpackage
and the former package-private classes has been renamed with a Jackson2
qualifier.

Closes spring-projectsgh-17832
Signed-off-by: Sébastien Deleuze <[email protected]>
@jvalkeal
Copy link
Contributor

@sdeleuze @rwinch I was wondering if message converters in oauth2-core will also be part of this PR.

static {
ClassLoader classLoader = HttpMessageConverters.class.getClassLoader();
jackson2Present = ClassUtils.isPresent("com.fasterxml.jackson.databind.ObjectMapper", classLoader)
&& ClassUtils.isPresent("com.fasterxml.jackson.core.JsonGenerator", classLoader);
gsonPresent = ClassUtils.isPresent("com.google.gson.Gson", classLoader);
jsonbPresent = ClassUtils.isPresent("jakarta.json.bind.Jsonb", classLoader);
}

That's then causing NPE's i.e in OAuth2AccessTokenResponseHttpMessageConverter as jsonMessageConverter will always be null. Same with other classes in that same package if I only have jackson3 in a classpath.

sdeleuze added a commit to sdeleuze/spring-security that referenced this pull request Sep 28, 2025
Since this module was already using the jackson sub-package for Jackson 2
support, both Jackson 2 and Jackson 3 support lives in the same subpackage
and the former package-private classes has been renamed with a Jackson2
qualifier.

See spring-projectsgh-17832
Signed-off-by: Sébastien Deleuze <[email protected]>
sdeleuze added a commit to sdeleuze/spring-security that referenced this pull request Sep 28, 2025
This commits remove global default typing for better security
and use instead a custom PolymorphicTypeValidator. See
https://cowtowncoder.medium.com/jackson-2-10-safe-default-typing-2d018f0ce2ba
for more details.

See spring-projectsgh-17832
Signed-off-by: Sébastien Deleuze <[email protected]>
@sdeleuze
Copy link
Contributor Author

@jvalkeal Good catch, I will add a related commit.

sdeleuze added a commit to sdeleuze/spring-security that referenced this pull request Oct 3, 2025
See spring-projectsgh-17832
Signed-off-by: Sébastien Deleuze <[email protected]>
sdeleuze added a commit to sdeleuze/spring-security that referenced this pull request Oct 3, 2025
This commit adds support for Jackson 3 which has the following
major differences with the Jackson 2 one:
 - jackson subpackage instead of jackson2
 - Jackson type prefix instead of Jackson2
 - JsonMapper instead of ObjectMapper
 - For configuration, JsonMapper.Builder instead of ObjectMapper
   since the latter is now immutable
 - Remove custom Jackson 3 support for unmodifiable collections
 - AllowlistTypeResolverBuilder in new a public type in order
   to be used easily with the JsonMapper.Builder API

Jackson 3 changes compared to Jackson 2 are documented on
FasterXML/jackson-future-ideas#72.

This commit does not cover webauthn which is a special case (uses
jackson sub-package for Jackson 2 support) which will be handled in
a distinct commit.

See spring-projectsgh-17832
Signed-off-by: Sébastien Deleuze <[email protected]>
sdeleuze added a commit to sdeleuze/spring-security that referenced this pull request Oct 3, 2025
This commit does not cover webauthn which is a special case (uses
jackson sub-package for Jackson 2 support) which will be handled in
a distinct commit.

See spring-projectsgh-17832
Signed-off-by: Sébastien Deleuze <[email protected]>
sdeleuze added a commit to sdeleuze/spring-security that referenced this pull request Oct 3, 2025
Since this module was already using the jackson sub-package for Jackson 2
support, both Jackson 2 and Jackson 3 support lives in the same subpackage
and the former package-private classes has been renamed with a Jackson2
qualifier.

See spring-projectsgh-17832
Signed-off-by: Sébastien Deleuze <[email protected]>
sdeleuze added a commit to sdeleuze/spring-security that referenced this pull request Oct 3, 2025
This commits remove global default typing for better security
and use instead a custom PolymorphicTypeValidator which can be
configured by each Spring Security module and customized by the
end users.

See
https://cowtowncoder.medium.com/jackson-2-10-safe-default-typing-2d018f0ce2ba
for more details.

See spring-projectsgh-17832
Signed-off-by: Sébastien Deleuze <[email protected]>
sdeleuze added a commit to sdeleuze/spring-security that referenced this pull request Oct 3, 2025
This commit introduces classpath checks and instantiation of
JacksonJsonHttpMessageConverter (based on Jackson 3) leveraging
a new GenericHttpMessageConverterAdapter which allows to adapt
SmartHttpMessageConverter to GenericHttpMessageConverter.

Closes spring-projectsgh-17832
Signed-off-by: Sébastien Deleuze <[email protected]>
sdeleuze and others added 10 commits October 19, 2025 16:31
Signed-off-by: Sébastien Deleuze <[email protected]>
See spring-projectsgh-17832
Signed-off-by: Sébastien Deleuze <[email protected]>
This commit adds support for Jackson 3 which has the following
major differences with the Jackson 2 one:
 - jackson subpackage instead of jackson2
 - Jackson type prefix instead of Jackson2
 - JsonMapper instead of ObjectMapper
 - For configuration, JsonMapper.Builder instead of ObjectMapper
   since the latter is now immutable
 - Remove custom support for unmodifiable collections
 - Use safe default typing via a PolymorphicTypeValidator

Jackson 3 changes compared to Jackson 2 are documented in
https://cowtowncoder.medium.com/jackson-3-0-0-ga-released-1f669cda529a
and
https://github.com/FasterXML/jackson/blob/main/jackson3/MIGRATING_TO_JACKSON_3.md.

This commit does not cover webauthn which is a special case (uses
jackson sub-package for Jackson 2 support) which will be handled in
a distinct commit.

See spring-projectsgh-17832
Signed-off-by: Sébastien Deleuze <[email protected]>
This commit does not cover webauthn which is a special case (uses
jackson sub-package for Jackson 2 support) which will be handled in
a distinct commit.

See spring-projectsgh-17832
Signed-off-by: Sébastien Deleuze <[email protected]>
Since this module was already using the jackson sub-package for Jackson 2
support, both Jackson 2 and Jackson 3 support lives in the same subpackage
and the former package-private classes has been renamed with a Jackson2
qualifier.

See spring-projectsgh-17832
Signed-off-by: Sébastien Deleuze <[email protected]>
This commit introduces classpath checks and instantiation of
JacksonJsonHttpMessageConverter (based on Jackson 3) leveraging
a new GenericHttpMessageConverterAdapter which allows to adapt
SmartHttpMessageConverter to GenericHttpMessageConverter.

See spring-projectsgh-17832
Signed-off-by: Sébastien Deleuze <[email protected]>
This commit refines the documentation by:
 - Updating Jackson documentation for Jackson 3
 - Removing the outdated documentation in servlet
 - Adding migration guidelines

Closes spring-projectsgh-17832
Signed-off-by: Sébastien Deleuze <[email protected]>
Without this many of the tests fail when using Jackson 3
- We should not introduce an unnecessary public API
  - It would need to be removed when Jackson 2 support was removed, but
    was required to configure Jackson 3 support
  - There are already existing interfaces that could be used
- OAuth2AuthorizationRowMapper & OAuth2AuthorizationParametersMapper had
  unnecessary breaking changes by removing getter/setter for ObjectMapper
- To prevent NoClassDefFoundErrors all optional (Jackson) dependencies
  need to be on different classes & we wish to preserve the existing
  accessors for ObjectMapper which is this uses subclasses
- With added TestAuthenticationTokenMixin support, no need to explicitly
  add it in tests
…eConverter)

This makes sense given that Framework's new Jackson support is a
SmartHttpMessageConverter. Additionally,
GenericHttpMessageConverterAdapter is now package private to encapsulate
it.

Issue spring-projectsgh-18073
@rwinch rwinch enabled auto-merge (rebase) October 19, 2025 21:48
@rwinch rwinch removed the status: waiting-for-triage An issue we've not yet triaged label Oct 19, 2025
@rwinch rwinch self-assigned this Oct 19, 2025
@rwinch rwinch added in: core An issue in spring-security-core type: enhancement A general enhancement labels Oct 19, 2025
@rwinch rwinch added this to the 7.0.0-RC1 milestone Oct 19, 2025
@rwinch rwinch merged commit 9dc27be into spring-projects:main Oct 19, 2025
6 checks passed
rwinch pushed a commit that referenced this pull request Oct 19, 2025
See gh-17832
Signed-off-by: Sébastien Deleuze <[email protected]>
rwinch pushed a commit that referenced this pull request Oct 19, 2025
This commit adds support for Jackson 3 which has the following
major differences with the Jackson 2 one:
 - jackson subpackage instead of jackson2
 - Jackson type prefix instead of Jackson2
 - JsonMapper instead of ObjectMapper
 - For configuration, JsonMapper.Builder instead of ObjectMapper
   since the latter is now immutable
 - Remove custom support for unmodifiable collections
 - Use safe default typing via a PolymorphicTypeValidator

Jackson 3 changes compared to Jackson 2 are documented in
https://cowtowncoder.medium.com/jackson-3-0-0-ga-released-1f669cda529a
and
https://github.com/FasterXML/jackson/blob/main/jackson3/MIGRATING_TO_JACKSON_3.md.

This commit does not cover webauthn which is a special case (uses
jackson sub-package for Jackson 2 support) which will be handled in
a distinct commit.

See gh-17832
Signed-off-by: Sébastien Deleuze <[email protected]>
rwinch pushed a commit that referenced this pull request Oct 19, 2025
This commit does not cover webauthn which is a special case (uses
jackson sub-package for Jackson 2 support) which will be handled in
a distinct commit.

See gh-17832
Signed-off-by: Sébastien Deleuze <[email protected]>
rwinch pushed a commit that referenced this pull request Oct 19, 2025
Since this module was already using the jackson sub-package for Jackson 2
support, both Jackson 2 and Jackson 3 support lives in the same subpackage
and the former package-private classes has been renamed with a Jackson2
qualifier.

See gh-17832
Signed-off-by: Sébastien Deleuze <[email protected]>
rwinch pushed a commit that referenced this pull request Oct 19, 2025
This commit introduces classpath checks and instantiation of
JacksonJsonHttpMessageConverter (based on Jackson 3) leveraging
a new GenericHttpMessageConverterAdapter which allows to adapt
SmartHttpMessageConverter to GenericHttpMessageConverter.

See gh-17832
Signed-off-by: Sébastien Deleuze <[email protected]>
rwinch pushed a commit that referenced this pull request Oct 19, 2025
This commit refines the documentation by:
 - Updating Jackson documentation for Jackson 3
 - Removing the outdated documentation in servlet
 - Adding migration guidelines

Closes gh-17832
Signed-off-by: Sébastien Deleuze <[email protected]>
@rwinch
Copy link
Member

rwinch commented Oct 19, 2025

Thank you for all of your hard work on this @sdeleuze This, along with some changes, have been merged into main. You can see the commits on this PR for details around the changes that were applied. I've also created some tickets to resolve some remaining issues:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

in: core An issue in spring-security-core type: enhancement A general enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants