mirror of
https://github.com/spring-projects/spring-security.git
synced 2025-10-21 09:48:46 +00:00
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 <sdeleuze@users.noreply.github.com>
31 lines
1.4 KiB
Plaintext
31 lines
1.4 KiB
Plaintext
[[jackson]]
|
|
= Jackson Support
|
|
|
|
Spring Security provides Jackson support for persisting Spring Security-related classes.
|
|
This can improve the performance of serializing Spring Security-related classes when working with distributed sessions (session replication, Spring Session, and so on).
|
|
|
|
To use it, register the `SecurityJacksonModules.getModules(ClassLoader)` with `JsonMapper.Builder` (https://github.com/FasterXML/jackson-databind[jackson-databind]):
|
|
|
|
[source,java]
|
|
----
|
|
ClassLoader loader = getClass().getClassLoader();
|
|
JsonMapper mapper = JsonMapper.builder()
|
|
.addModules(SecurityJacksonModules.getModules(loader))
|
|
.build();
|
|
|
|
// ... use JsonMapper as normally ...
|
|
SecurityContext context = new SecurityContextImpl();
|
|
// ...
|
|
String json = mapper.writeValueAsString(context);
|
|
----
|
|
|
|
[NOTE]
|
|
====
|
|
The following Spring Security modules provide Jackson support:
|
|
|
|
- spring-security-core (javadoc:org.springframework.security.jackson.CoreJacksonModule[])
|
|
- 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[])
|
|
- <<oauth2client, spring-security-oauth2-client>> (javadoc:org.springframework.security.oauth2.client.jackson.OAuth2ClientJacksonModule[])
|
|
- spring-security-cas (javadoc:org.springframework.security.cas.jackson.CasJacksonModule[])
|
|
====
|