Spring Security 为 Jackson 提供了对持久化 Spring Security 相关类的支持。 这可以提高在处理分布式会话(会话复制、Spring Session 等)时序列化 Spring Security 相关类的性能。Spring中文文档

要使用它,请注册 (jackson-databind):SecurityJackson2Modules.getModules(ClassLoader)ObjectMapperSpring中文文档

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 Security 模块提供 Jackson 支持:Spring中文文档