Class BasicPolymorphicTypeValidator
- java.lang.Object
-
- com.fasterxml.jackson.databind.jsontype.PolymorphicTypeValidator
-
- com.fasterxml.jackson.databind.jsontype.PolymorphicTypeValidator.Base
-
- com.fasterxml.jackson.databind.jsontype.BasicPolymorphicTypeValidator
-
- All Implemented Interfaces:
Serializable
public class BasicPolymorphicTypeValidator extends PolymorphicTypeValidator.Base implements Serializable
StandardBasicPolymorphicTypeValidatorimplementation 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:- Since:
- 2.10
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classBasicPolymorphicTypeValidator.BuilderBuilder class for configuring and constructing immutableBasicPolymorphicTypeValidatorinstances.protected static classBasicPolymorphicTypeValidator.NameMatcherGeneral matcher interface (predicate) for validating unresolved subclass class name.protected static classBasicPolymorphicTypeValidator.TypeMatcherGeneral matcher interface (predicate) for validating class values (base type or resolved subtype)-
Nested classes/interfaces inherited from class com.fasterxml.jackson.databind.jsontype.PolymorphicTypeValidator
PolymorphicTypeValidator.Base, PolymorphicTypeValidator.Validity
-
-
Field Summary
Fields Modifier and Type Field Description protected BasicPolymorphicTypeValidator.TypeMatcher[]_baseTypeMatchersSet of matchers that can validate all values of polymorphic properties that match specified allowed base types.protected Set<Class<?>>_invalidBaseTypesSet of specifically denied base types to indicate that use of specific base types is not allowed: most commonly used to fully block use ofObjectas the base type.protected BasicPolymorphicTypeValidator.TypeMatcher[]_subClassMatchersSet of matchers that can validate specific values of polymorphic properties that match subtype class criteria.protected BasicPolymorphicTypeValidator.NameMatcher[]_subTypeNameMatchersSet of matchers that can validate specific values of polymorphic properties that match subtype class name criteria.
-
Constructor Summary
Constructors Modifier Constructor Description protectedBasicPolymorphicTypeValidator(Set<Class<?>> invalidBaseTypes, BasicPolymorphicTypeValidator.TypeMatcher[] baseTypeMatchers, BasicPolymorphicTypeValidator.NameMatcher[] subTypeNameMatchers, BasicPolymorphicTypeValidator.TypeMatcher[] subClassMatchers)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static BasicPolymorphicTypeValidator.Builderbuilder()PolymorphicTypeValidator.ValidityvalidateBaseType(MapperConfig<?> ctxt, JavaType baseType)Method called when a property with polymorphic value is encountered, and aTypeResolverBuilderis needed.PolymorphicTypeValidator.ValidityvalidateSubClassName(MapperConfig<?> ctxt, JavaType baseType, String subClassName)PolymorphicTypeValidator.ValidityvalidateSubType(MapperConfig<?> ctxt, JavaType baseType, JavaType subType)Method called after class name has been resolved to actual type, in cases where previous call toPolymorphicTypeValidator.validateSubClassName(com.fasterxml.jackson.databind.cfg.MapperConfig<?>, com.fasterxml.jackson.databind.JavaType, java.lang.String)returnedPolymorphicTypeValidator.Validity.INDETERMINATE.
-
-
-
Field Detail
-
_invalidBaseTypes
protected final Set<Class<?>> _invalidBaseTypes
Set of specifically denied base types to indicate that use of specific base types is not allowed: most commonly used to fully block use ofObjectas the base type.
-
_baseTypeMatchers
protected final BasicPolymorphicTypeValidator.TypeMatcher[] _baseTypeMatchers
Set of matchers that can validate all values of polymorphic properties that match specified allowed base types.
-
_subTypeNameMatchers
protected final BasicPolymorphicTypeValidator.NameMatcher[] _subTypeNameMatchers
Set of matchers that can validate specific values of polymorphic properties that match subtype class name criteria.
-
_subClassMatchers
protected final BasicPolymorphicTypeValidator.TypeMatcher[] _subClassMatchers
Set of matchers that can validate specific values of polymorphic properties that match subtype class criteria.
-
-
Constructor Detail
-
BasicPolymorphicTypeValidator
protected BasicPolymorphicTypeValidator(Set<Class<?>> invalidBaseTypes, BasicPolymorphicTypeValidator.TypeMatcher[] baseTypeMatchers, BasicPolymorphicTypeValidator.NameMatcher[] subTypeNameMatchers, BasicPolymorphicTypeValidator.TypeMatcher[] subClassMatchers)
-
-
Method Detail
-
builder
public static BasicPolymorphicTypeValidator.Builder builder()
-
validateBaseType
public PolymorphicTypeValidator.Validity validateBaseType(MapperConfig<?> ctxt, JavaType baseType)
Description copied from class:PolymorphicTypeValidatorMethod called when a property with polymorphic value is encountered, and aTypeResolverBuilderis needed. Intent is to allow early determination of cases where subtyping is completely denied (for example for security reasons), or, conversely, allowed for allow subtypes (when base type guarantees that all subtypes are known to be safe). Check can be thought of as both optimization (for latter case) and eager-fail (for former case) to give better feedback.- Overrides:
validateBaseTypein classPolymorphicTypeValidator.Base- Parameters:
ctxt- Configuration for resolution: typically will beDeserializationConfigbaseType- Nominal base type used for polymorphic handling: subtypes MUST be instances of this type and assignment compatibility is verified by Jackson core- Returns:
- Determination of general validity of all subtypes of given base type; if
PolymorphicTypeValidator.Validity.ALLOWEDreturned, all subtypes will automatically be accepted without further checks; isPolymorphicTypeValidator.Validity.DENIEDreturned no subtyping allowed at all (caller will usually throw an exception); otherwise (returnPolymorphicTypeValidator.Validity.INDETERMINATE) per sub-type validation calls are made for each new subclass encountered.
-
validateSubClassName
public PolymorphicTypeValidator.Validity validateSubClassName(MapperConfig<?> ctxt, JavaType baseType, String subClassName) throws JsonMappingException
Description copied from class:PolymorphicTypeValidatorMethod called after intended class name for subtype has been read (and in case of minimal class name, expanded to fully-qualified class name) but before attempt is made to look up actualClassorJavaType. Validator may be able to determine validity of eventual type (and returnPolymorphicTypeValidator.Validity.ALLOWEDorPolymorphicTypeValidator.Validity.DENIED) or, if not able to, can defer validation to actual resolved type by returningPolymorphicTypeValidator.Validity.INDETERMINATE.Validator may also choose to indicate denial by throwing a
JsonMappingException(such asInvalidTypeIdException)- Overrides:
validateSubClassNamein classPolymorphicTypeValidator.Base- Parameters:
ctxt- Configuration for resolution: typically will beDeserializationConfigbaseType- Nominal base type used for polymorphic handling: subtypes MUST be instances of this type and assignment compatibility is verified by Jackson coresubClassName- Name of class that will be resolved toClassif (and only if) validity check is not denied.- Returns:
- Determination of validity of given class name, as a subtype of given base type:
should NOT return
null - Throws:
JsonMappingException
-
validateSubType
public PolymorphicTypeValidator.Validity validateSubType(MapperConfig<?> ctxt, JavaType baseType, JavaType subType) throws JsonMappingException
Description copied from class:PolymorphicTypeValidatorMethod called after class name has been resolved to actual type, in cases where previous call toPolymorphicTypeValidator.validateSubClassName(com.fasterxml.jackson.databind.cfg.MapperConfig<?>, com.fasterxml.jackson.databind.JavaType, java.lang.String)returnedPolymorphicTypeValidator.Validity.INDETERMINATE. Validator should be able to determine validity and return appropriatePolymorphicTypeValidator.Validityvalue, although it may alsoValidator may also choose to indicate denial by throwing a
JsonMappingException(such asInvalidTypeIdException)- Overrides:
validateSubTypein classPolymorphicTypeValidator.Base- Parameters:
ctxt- Configuration for resolution: typically will beDeserializationConfigbaseType- Nominal base type used for polymorphic handling: subtypes MUST be instances of this type and assignment compatibility has been verified by Jackson coresubType- Resolved subtype to validate- Returns:
- Determination of validity of given class name, as a subtype of given base type:
should NOT return
null - Throws:
JsonMappingException
-
-