public class BasicPolymorphicTypeValidator extends PolymorphicTypeValidator.Base implements Serializable
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:
Modifier and Type | Class and Description |
---|---|
static class |
BasicPolymorphicTypeValidator.Builder
Builder class for configuring and constructing immutable
BasicPolymorphicTypeValidator instances. |
static class |
BasicPolymorphicTypeValidator.NameMatcher
General matcher interface (predicate) for validating unresolved
subclass class name.
|
static class |
BasicPolymorphicTypeValidator.TypeMatcher
General matcher interface (predicate) for validating class values
(base type or resolved subtype)
|
PolymorphicTypeValidator.Base, PolymorphicTypeValidator.Validity
Modifier and Type | Field and Description |
---|---|
protected BasicPolymorphicTypeValidator.TypeMatcher[] |
_baseTypeMatchers
Set of matchers that can validate all values of polymorphic properties
that match specified allowed base types.
|
protected 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 of
Object as the base type. |
protected BasicPolymorphicTypeValidator.TypeMatcher[] |
_subClassMatchers
Set of matchers that can validate specific values of polymorphic properties
that match subtype class criteria.
|
protected BasicPolymorphicTypeValidator.NameMatcher[] |
_subTypeNameMatchers
Set of matchers that can validate specific values of polymorphic properties
that match subtype class name criteria.
|
Modifier | Constructor and Description |
---|---|
protected |
BasicPolymorphicTypeValidator(Set<Class<?>> invalidBaseTypes,
BasicPolymorphicTypeValidator.TypeMatcher[] baseTypeMatchers,
BasicPolymorphicTypeValidator.NameMatcher[] subTypeNameMatchers,
BasicPolymorphicTypeValidator.TypeMatcher[] subClassMatchers) |
Modifier and Type | Method and Description |
---|---|
static BasicPolymorphicTypeValidator.Builder |
builder() |
PolymorphicTypeValidator.Validity |
validateBaseType(MapperConfig<?> ctxt,
JavaType baseType)
Method called when a property with polymorphic value is encountered, and a
TypeResolverBuilder is needed. |
PolymorphicTypeValidator.Validity |
validateSubClassName(MapperConfig<?> ctxt,
JavaType baseType,
String subClassName)
|
PolymorphicTypeValidator.Validity |
validateSubType(MapperConfig<?> ctxt,
JavaType baseType,
JavaType subType)
Method called after class name has been resolved to actual type, in cases where previous
call to
PolymorphicTypeValidator.validateSubClassName(com.fasterxml.jackson.databind.cfg.MapperConfig<?>, com.fasterxml.jackson.databind.JavaType, java.lang.String) returned PolymorphicTypeValidator.Validity.INDETERMINATE . |
protected final Set<Class<?>> _invalidBaseTypes
Object
as the base type.protected final BasicPolymorphicTypeValidator.TypeMatcher[] _baseTypeMatchers
protected final BasicPolymorphicTypeValidator.NameMatcher[] _subTypeNameMatchers
protected final BasicPolymorphicTypeValidator.TypeMatcher[] _subClassMatchers
protected BasicPolymorphicTypeValidator(Set<Class<?>> invalidBaseTypes, BasicPolymorphicTypeValidator.TypeMatcher[] baseTypeMatchers, BasicPolymorphicTypeValidator.NameMatcher[] subTypeNameMatchers, BasicPolymorphicTypeValidator.TypeMatcher[] subClassMatchers)
public static BasicPolymorphicTypeValidator.Builder builder()
public PolymorphicTypeValidator.Validity validateBaseType(MapperConfig<?> ctxt, JavaType baseType)
PolymorphicTypeValidator
TypeResolverBuilder
is 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.validateBaseType
in class PolymorphicTypeValidator.Base
ctxt
- Configuration for resolution: typically will be DeserializationConfig
baseType
- Nominal base type used for polymorphic handling: subtypes MUST be instances
of this type and assignment compatibility is verified by Jackson corePolymorphicTypeValidator.Validity.ALLOWED
returned, all subtypes will automatically be accepted without
further checks; is PolymorphicTypeValidator.Validity.DENIED
returned no subtyping allowed at all
(caller will usually throw an exception); otherwise (return PolymorphicTypeValidator.Validity.INDETERMINATE
)
per sub-type validation calls are made for each new subclass encountered.public PolymorphicTypeValidator.Validity validateSubClassName(MapperConfig<?> ctxt, JavaType baseType, String subClassName) throws JsonMappingException
PolymorphicTypeValidator
Class
or JavaType
.
Validator may be able to
determine validity of eventual type (and return PolymorphicTypeValidator.Validity.ALLOWED
or
PolymorphicTypeValidator.Validity.DENIED
) or, if not able to, can defer validation to actual
resolved type by returning PolymorphicTypeValidator.Validity.INDETERMINATE
.
Validator may also choose to indicate denial by throwing a JsonMappingException
(such as InvalidTypeIdException
)
validateSubClassName
in class PolymorphicTypeValidator.Base
ctxt
- Configuration for resolution: typically will be DeserializationConfig
baseType
- 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 to Class
if
(and only if) validity check is not denied.null
JsonMappingException
public PolymorphicTypeValidator.Validity validateSubType(MapperConfig<?> ctxt, JavaType baseType, JavaType subType) throws JsonMappingException
PolymorphicTypeValidator
PolymorphicTypeValidator.validateSubClassName(com.fasterxml.jackson.databind.cfg.MapperConfig<?>, com.fasterxml.jackson.databind.JavaType, java.lang.String)
returned PolymorphicTypeValidator.Validity.INDETERMINATE
.
Validator should be able to determine validity and return appropriate PolymorphicTypeValidator.Validity
value, although it may also
Validator may also choose to indicate denial by throwing a JsonMappingException
(such as InvalidTypeIdException
)
validateSubType
in class PolymorphicTypeValidator.Base
ctxt
- Configuration for resolution: typically will be DeserializationConfig
baseType
- 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 validatenull
JsonMappingException
Copyright © 2021 JBoss by Red Hat. All rights reserved.