# Jackson支助 Spring 安全性为持久化 Spring 与安全性相关的类提供了Jackson支持。这可以在使用分布式会话(即会话复制、 Spring 会话等)时提高序列化 Spring 安全相关类的性能。 要使用它,将`SecurityJackson2Modules.getModules(ClassLoader)`注册为`ObjectMapper`([Jackson-数据库](https://github.com/FasterXML/jackson-databind)): ``` ObjectMapper mapper = new ObjectMapper(); ClassLoader loader = getClass().getClassLoader(); List modules = SecurityJackson2Modules.getModules(loader); mapper.registerModules(modules); // ... use ObjectMapper as normally ... SecurityContext context = new SecurityContextImpl(); // ... String json = mapper.writeValueAsString(context); ``` | |以下 Spring 安全模块提供了Jackson支持:

* Spring-security-core(`CoreJackson2Module`)

* Spring-security-web(`WebJackson2Module`,`WebServletJackson2Module`,`WebServerJackson2Module`)
(<11"gt="9"/>r=“r=”/>(<18"r="19"r=">>>>>(<<<<>>>>>| |---|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| [并发性](concurrency.html)[本地化](localization.html)