|
对于最新的稳定版本,请使用 Spring Security 7.0.4! |
Jackson 支持
Spring Security 提供了对 Jackson 的支持,用于持久化 Spring Security 相关的类。 这可以在处理分布式会话(即会话复制、Spring Session 等)时提高序列化 Spring Security 相关类的性能。
要使用它,请将SecurityJackson2Modules.getModules(ClassLoader)注册到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 的支持:
|