Class SecurityJacksonModules

java.lang.Object
org.springframework.security.jackson.SecurityJacksonModules

public final class SecurityJacksonModules extends Object
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 Type
    Method
    Description
    static List<tools.jackson.databind.JacksonModule>
    Return the list of available security modules in classpath, enable automatic inclusion of type information and configure a default PolymorphicTypeValidator that 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 default PolymorphicTypeValidator customizable with the provided builder that handles the validation of class names.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • getModules

      public static 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 default PolymorphicTypeValidator that 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 default PolymorphicTypeValidator customizable with the provided builder that handles the validation of class names.
      Parameters:
      loader - the ClassLoader to use
      typeValidatorBuilder - the builder to configure custom types allowed in addition to Spring Security ones
      Returns:
      List of available security modules in classpath.