servlet-integrations-jackson.md 1.5 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
# 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<Module> modules = SecurityJackson2Modules.getModules(loader);
mapper.registerModules(modules);

// ... use ObjectMapper as normally ...
SecurityContext context = new SecurityContextImpl();
// ...
String json = mapper.writeValueAsString(context);
```

|   |以下 Spring 安全模块提供了Jackson支持:<br/><br/>* Spring-security-core(`CoreJackson2Module`)<br/><br/>* Spring-security-web(`WebJackson2Module``WebServletJackson2Module``WebServerJackson2Module`<br/><11"gt="9"/>r=“r=”/>(<18"r="19"r=">>>>>(<<<<<gt="r="10">>>>>>|
|---|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|

[并发性](concurrency.html)[本地化](localization.html)