最新の安定バージョンについては、Spring Security 6.4.4 を使用してください! |
Jackson サポート
Spring Security は、Spring Security 関連クラスを永続化するための Jackson サポートを提供します。これにより、分散セッション(つまり、セッションレプリケーション、Spring Session など)で作業する際に Spring Security 関連クラスを直列化するパフォーマンスを改善できます。
使用するには、SecurityJackson2Modules.getModules(ClassLoader)
を ObjectMapper
に登録します(jackson-databind [GitHub] (英語) ):
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 サポートを提供します。
|