Class BasicPolymorphicTypeValidator

  • All Implemented Interfaces:
    java.io.Serializable

    public class BasicPolymorphicTypeValidator
    extends PolymorphicTypeValidator.Base
    implements java.io.Serializable
    Standard BasicPolymorphicTypeValidator implementation that users may want to use for constructing validators based on simple class hierarchy and/or name patterns to allow and/or deny certain subtypes.

    Most commonly this is used to allow known safe subtypes based on common super type or Java package name.
    For example:

     PolymorphicTypeValidator ptv = BasicPolymorphicTypeValidator.builder()
         // base type that polymorphism is enabled for
         .allowIfBaseType(MyValue.class)
         // accept any subtype of MyValue under our own package
         .allowIfSubType("com.example.values.")
         // and any concrete subtype of this specific safe interface
         .allowIfSubType(SafeMarker.class)
         .build();
    
      ObjectMapper mapper = JsonMapper.builder()
              .activateDefaultTyping(ptv, DefaultTyping.NON_FINAL)
              .build();
    
    Since:
    2.10
    See Also:
    Serialized Form