jackson.adoc 1.4 KB

123456789101112131415161718192021222324252627282930
  1. [[jackson]]
  2. = Jackson Support
  3. Spring Security provides Jackson support for persisting Spring Security-related classes.
  4. This can improve the performance of serializing Spring Security-related classes when working with distributed sessions (session replication, Spring Session, and so on).
  5. To use it, register the `SecurityJackson2Modules.getModules(ClassLoader)` with `ObjectMapper` (https://github.com/FasterXML/jackson-databind[jackson-databind]):
  6. [source,java]
  7. ----
  8. ObjectMapper mapper = new ObjectMapper();
  9. ClassLoader loader = getClass().getClassLoader();
  10. List<Module> modules = SecurityJackson2Modules.getModules(loader);
  11. mapper.registerModules(modules);
  12. // ... use ObjectMapper as normally ...
  13. SecurityContext context = new SecurityContextImpl();
  14. // ...
  15. String json = mapper.writeValueAsString(context);
  16. ----
  17. [NOTE]
  18. ====
  19. The following Spring Security modules provide Jackson support:
  20. - spring-security-core (javadoc:org.springframework.security.jackson2.CoreJackson2Module[])
  21. - spring-security-web (javadoc:org.springframework.security.web.jackson2.WebJackson2Module[], javadoc:org.springframework.security.web.jackson2.WebServletJackson2Module[], javadoc:org.springframework.security.web.server.jackson2.WebServerJackson2Module[])
  22. - <<oauth2client, spring-security-oauth2-client>> (javadoc:org.springframework.security.oauth2.client.jackson2.OAuth2ClientJackson2Module[])
  23. - spring-security-cas (javadoc:org.springframework.security.cas.jackson2.CasJackson2Module[])
  24. ====