Jackson 支援
Spring Security 為持久化 Spring Security 相關類提供了 Jackson 支援。在使用分散式會話(即會話複製、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 支援
|