Skip to content

Commit 8f8a255

Browse files
sdeleuzerwinch
authored andcommitted
Refine documentation for Jackson 3
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]>
1 parent 137f8fd commit 8f8a255

File tree

4 files changed

+66
-37
lines changed

4 files changed

+66
-37
lines changed

docs/modules/ROOT/nav.adoc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@
110110
*** xref:servlet/exploits/firewall.adoc[]
111111
** xref:servlet/integrations/index.adoc[Integrations]
112112
*** xref:servlet/integrations/concurrency.adoc[Concurrency]
113-
*** xref:servlet/integrations/jackson.adoc[Jackson]
114113
*** xref:servlet/integrations/localization.adoc[Localization]
115114
*** xref:servlet/integrations/servlet-api.adoc[Servlet APIs]
116115
*** xref:servlet/integrations/data.adoc[Spring Data]

docs/modules/ROOT/pages/features/integrations/jackson.adoc

Lines changed: 48 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
[[jackson]]
22
= Jackson Support
33

4-
Spring Security provides Jackson support for persisting Spring Security related classes.
4+
Spring Security provides Jackson 3 support for persisting Spring Security related classes.
55
This can improve the performance of serializing Spring Security related classes when working with distributed sessions (i.e. session replication, Spring Session, etc).
66

7-
To use it, register the `SecurityJacksonModules.getModules(ClassLoader)` with `JsonMapper.Builder` (https://github.com/FasterXML/jackson-databind[jackson-databind]):
7+
[NOTE]
8+
====
9+
Jackson 2 support is still available but deprecated for removal, so you are encouraged to migrate to Jackson 3.
10+
====
11+
12+
To use it, register `SecurityJacksonModules.getModules(ClassLoader)` with `JsonMapper.Builder` (https://github.com/FasterXML/jackson-databind[jackson-databind]):
813

914
[tabs]
1015
======
@@ -39,12 +44,49 @@ val json: String = mapper.writeValueAsString(context)
3944
----
4045
======
4146

47+
[NOTE]
48+
====
49+
Using `SecurityJacksonModules` as above enables automatic inclusion of type information and configure a
50+
`PolymorphicTypeValidator` that handles the validation of class names.
51+
====
52+
53+
If needed, you can add custom classes to the validation handling.
54+
55+
[tabs]
56+
======
57+
Java::
58+
+
59+
[source,java,role="primary"]
60+
----
61+
ClassLoader loader = getClass().getClassLoader();
62+
BasicPolymorphicTypeValidator.Builder builder = BasicPolymorphicTypeValidator.builder()
63+
.allowIfSubType(MyCustomType.class);
64+
JsonMapper mapper = JsonMapper.builder()
65+
.addModules(SecurityJacksonModules.getModules(loader, builder))
66+
.build();
67+
----
68+
69+
Kotlin::
70+
+
71+
[source,kotlin,role="secondary"]
72+
----
73+
val loader = javaClass.classLoader
74+
val builder = BasicPolymorphicTypeValidator.builder()
75+
.allowIfSubType(MyCustomType::class)
76+
val mapper = JsonMapper.builder()
77+
.addModules(SecurityJacksonModules.getModules(loader, builder))
78+
.build()
79+
----
80+
======
81+
4282
[NOTE]
4383
====
4484
The following Spring Security modules provide Jackson support:
4585
46-
- spring-security-core (`CoreJacksonModule`)
47-
- spring-security-web (`WebJacksonModule`, `WebServletJacksonModule`, `WebServerJacksonModule`)
48-
- xref:servlet/oauth2/client/index.adoc#oauth2client[ spring-security-oauth2-client] (`OAuth2ClientJacksonModule`)
49-
- spring-security-cas (`CasJacksonModule`)
86+
- spring-security-core (javadoc:org.springframework.security.jackson.CoreJacksonModule[])
87+
- spring-security-web (javadoc:org.springframework.security.web.jackson.WebJacksonModule[], javadoc:org.springframework.security.web.jackson.WebServletJacksonModule[], javadoc:org.springframework.security.web.server.jackson.WebServerJacksonModule[])
88+
- spring-security-oauth2-client (javadoc:org.springframework.security.oauth2.client.jackson.OAuth2ClientJacksonModule[])
89+
- spring-security-cas (javadoc:org.springframework.security.cas.jackson.CasJacksonModule[])
90+
- spring-security-ldap (javadoc:org.springframework.security.ldap.jackson.LdapJacksonModule[])
91+
- spring-security-saml2 (javadoc:org.springframework.security.saml2.jackson.Saml2JacksonModule[])
5092
====

docs/modules/ROOT/pages/migration/index.adoc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,24 @@ The first step is to ensure you are the latest patch release of Spring Boot 4.0.
1616
Next, you should ensure you are on the latest patch release of Spring Security 7.
1717
For directions, on how to update to Spring Security 7 visit the xref:getting-spring-security.adoc[] section of the reference guide.
1818

19+
=== Migrate from Jackson 2 to Jackson 3
20+
21+
The configuration of Jackson 2 `ObjectMapper` with `SecurityJackson2Modules` should be replaced by the configuration of
22+
Jackson 3 `JsonMapper.Builder` with `SecurityJacksonModules`. See the
23+
https://github.com/FasterXML/jackson/blob/main/jackson3/MIGRATING_TO_JACKSON_3.md[Jackson 3 Migration Guide] for more details.
24+
25+
It is recommended to replace the configuration of
26+
individual modules like `CoreJacksonModule` by the module detection from `SecurityJacksonModules` as it enables
27+
automatic inclusion of type information and configure a `PolymorphicTypeValidator` that handles the validation of class
28+
names.
29+
30+
The Jackson 3 support uses the same format than the now deprecated Jackson 2 one, so class instances serialized with
31+
Jackson 2 should be deserializable with the Jackson 3 support.
32+
33+
`spring-security-oauth2-authorization-server` now uses Jackson 3 by default. If you want to continue
34+
to use the deprecated Jackson 2 support, the transitive dependency on Jackson 3 (`tools.jackson.core:jackson-databind`)
35+
should be excluded and a dependency on Jackson 2 (`com.fasterxml.jackson.core:jackson-databind`) should be added.
36+
1937
== Perform Application-Specific Steps
2038

2139
Next, there are steps you need to perform based on whether it is a xref:migration/servlet/index.adoc[Servlet] or xref:migration/reactive.adoc[Reactive] application.

docs/modules/ROOT/pages/servlet/integrations/jackson.adoc

Lines changed: 0 additions & 30 deletions
This file was deleted.

0 commit comments

Comments
 (0)