Jackson Support
Spring Security 提供了 Jackson 支持,用于持久存储与 Spring Security 相关的类。在使用分布式会话(即会话复制、Spring Session 等)处理与 Spring Security 相关的类时,这样做可以提高序列化性能。
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 (i.e. session replication, Spring Session, etc).
要使用它,请使用 ObjectMapper
( jackson-databind)向 SecurityJackson2Modules.getModules(ClassLoader)
注册:
To use it, register the SecurityJackson2Modules.getModules(ClassLoader)
with ObjectMapper
(jackson-databind):
-
Java
-
Kotlin
ObjectMapper mapper = new ObjectMapper();
ClassLoader loader = getClass().getClassLoader();
List<Module> modules = SecurityJackson2Modules.getModules(loader);
mapper.registerModules(modules);
// ... use ObjectMapper as normally ...
SecurityContext context = new SecurityContextImpl();
// ...
String json = mapper.writeValueAsString(context);
val mapper = ObjectMapper()
val loader = javaClass.classLoader
val modules: MutableList<Module> = SecurityJackson2Modules.getModules(loader)
mapper.registerModules(modules)
// ... use ObjectMapper as normally ...
val context: SecurityContext = SecurityContextImpl()
// ...
val json: String = mapper.writeValueAsString(context)
以下 Spring Security 模块提供 Jackson 支持: The following Spring Security modules provide Jackson support:
|