2016-09-23 13:02:27 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								[[jackson]]
							 
						 
					
						
							
								
									
										
										
										
											2021-07-30 13:52:15 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								= Jackson Support
							 
						 
					
						
							
								
									
										
										
										
											2016-09-23 13:02:27 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-03-18 13:59:40 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Spring Security provides Jackson support for persisting Spring Security related classes.
							 
						 
					
						
							
								
									
										
										
										
											2016-09-23 13:02:27 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								This can improve the performance of serializing Spring Security related classes when working with distributed sessions (i.e. session replication, Spring Session, etc).
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-03-18 13:59:40 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								To use it, register the `SecurityJackson2Modules.getModules(ClassLoader)` with `ObjectMapper` (https://github.com/FasterXML/jackson-databind[jackson-databind]):
							 
						 
					
						
							
								
									
										
										
										
											2016-09-23 13:02:27 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-06-18 21:30:41 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								[tabs]
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								======
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								Java::
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								+
							 
						 
					
						
							
								
									
										
										
										
											2021-06-16 10:31:29 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								[source,java,role="primary"]
							 
						 
					
						
							
								
									
										
										
										
											2016-09-23 13:02:27 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								----
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								ObjectMapper mapper = new ObjectMapper();
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								ClassLoader loader = getClass().getClassLoader();
							 
						 
					
						
							
								
									
										
										
										
											2016-11-09 16:40:24 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								List<Module> modules = SecurityJackson2Modules.getModules(loader);
							 
						 
					
						
							
								
									
										
										
										
											2016-09-23 13:02:27 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								mapper.registerModules(modules);
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// ... use ObjectMapper as normally ...
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								SecurityContext context = new SecurityContextImpl();
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// ...
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								String json = mapper.writeValueAsString(context);
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								----
							 
						 
					
						
							
								
									
										
										
										
											2020-03-18 13:59:40 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-06-18 21:30:41 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Kotlin::
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								+
							 
						 
					
						
							
								
									
										
										
										
											2021-06-16 10:31:29 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								[source,kotlin,role="secondary"]
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								----
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								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)
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								----
							 
						 
					
						
							
								
									
										
										
										
											2023-06-18 21:30:41 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								======
							 
						 
					
						
							
								
									
										
										
										
											2021-06-16 10:31:29 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-03-18 13:59:40 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								[NOTE]
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								====
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								The following Spring Security modules provide Jackson support:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								- spring-security-core (`CoreJackson2Module`)
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								- spring-security-web (`WebJackson2Module`, `WebServletJackson2Module`, `WebServerJackson2Module`)
							 
						 
					
						
							
								
									
										
										
										
											2021-11-04 11:31:27 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								- xref:servlet/oauth2/client/index.adoc#oauth2client[ spring-security-oauth2-client] (`OAuth2ClientJackson2Module`)
							 
						 
					
						
							
								
									
										
										
										
											2020-03-18 13:59:40 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								- spring-security-cas (`CasJackson2Module`)
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								====