Class SecurityJacksonModules
java.lang.Object
org.springframework.security.jackson.SecurityJacksonModules
This utility class will find all the Jackson modules contributed by Spring Security in
the classpath (except
OAuth2AuthorizationServerJacksonModule and
WebauthnJacksonModule), enable automatic inclusion of type information and
configure a PolymorphicTypeValidator that handles the validation of class
names.
ClassLoader loader = getClass().getClassLoader();
JsonMapper mapper = JsonMapper.builder()
.addModules(SecurityJacksonModules.getModules(loader))
.build();
If needed, you can add custom classes to the validation handling.
ClassLoader loader = getClass().getClassLoader();
BasicPolymorphicTypeValidator.Builder builder = BasicPolymorphicTypeValidator.builder()
.allowIfSubType(MyCustomType.class);
JsonMapper mapper = JsonMapper.builder()
.addModules(SecurityJacksonModules.getModules(loader, builder))
.build();
- Since:
- 7.0
-
Method Summary
Modifier and TypeMethodDescriptionstatic List<tools.jackson.databind.JacksonModule>getModules(ClassLoader loader) Return the list of available security modules in classpath, enable automatic inclusion of type information and configure a defaultPolymorphicTypeValidatorthat handles the validation of class names.static List<tools.jackson.databind.JacksonModule>getModules(ClassLoader loader, @Nullable tools.jackson.databind.jsontype.BasicPolymorphicTypeValidator.Builder typeValidatorBuilder) Return the list of available security modules in classpath, enable automatic inclusion of type information and configure a defaultPolymorphicTypeValidatorcustomizable with the provided builder that handles the validation of class names.
-
Method Details
-
getModules
Return the list of available security modules in classpath, enable automatic inclusion of type information and configure a defaultPolymorphicTypeValidatorthat handles the validation of class names.- Parameters:
loader- the ClassLoader to use- Returns:
- List of available security modules in classpath
- See Also:
-
getModules
public static List<tools.jackson.databind.JacksonModule> getModules(ClassLoader loader, @Nullable tools.jackson.databind.jsontype.BasicPolymorphicTypeValidator.Builder typeValidatorBuilder) Return the list of available security modules in classpath, enable automatic inclusion of type information and configure a defaultPolymorphicTypeValidatorcustomizable with the provided builder that handles the validation of class names.- Parameters:
loader- the ClassLoader to usetypeValidatorBuilder- the builder to configure custom types allowed in addition to Spring Security ones- Returns:
- List of available security modules in classpath.
-