public static class BasicPolymorphicTypeValidator.Builder extends Object
BasicPolymorphicTypeValidator
instances. Criteria for allowing
polymorphic subtypes is specified by adding rules in priority order, starting
with the rules to evaluate first: when a matching rule is found, its status
(PolymorphicTypeValidator.Validity.ALLOWED
or PolymorphicTypeValidator.Validity.DENIED
) is used and no further
rules are checked.Modifier and Type | Field and Description |
---|---|
protected List<BasicPolymorphicTypeValidator.TypeMatcher> |
_baseTypeMatchers
Collected matchers for base types to allow.
|
protected Set<Class<?>> |
_invalidBaseTypes
Optional set of base types (exact match) that are NOT accepted
as base types for polymorphic properties.
|
protected List<BasicPolymorphicTypeValidator.TypeMatcher> |
_subTypeClassMatchers
Collected Class-based matchers for sub types to allow.
|
protected List<BasicPolymorphicTypeValidator.NameMatcher> |
_subTypeNameMatchers
Collected name-based matchers for sub types to allow.
|
Modifier | Constructor and Description |
---|---|
protected |
Builder() |
Modifier and Type | Method and Description |
---|---|
protected BasicPolymorphicTypeValidator.Builder |
_appendBaseMatcher(BasicPolymorphicTypeValidator.TypeMatcher matcher) |
protected BasicPolymorphicTypeValidator.Builder |
_appendSubClassMatcher(BasicPolymorphicTypeValidator.TypeMatcher matcher) |
protected BasicPolymorphicTypeValidator.Builder |
_appendSubNameMatcher(BasicPolymorphicTypeValidator.NameMatcher matcher) |
BasicPolymorphicTypeValidator.Builder |
allowIfBaseType(BasicPolymorphicTypeValidator.TypeMatcher matcher)
Method for appending custom matcher called with base type: if matcher returns
true , all possible subtypes will be accepted; if false , other
matchers are applied. |
BasicPolymorphicTypeValidator.Builder |
allowIfBaseType(Class<?> baseOfBase)
Method for appending matcher that will allow all subtypes in cases where
nominal base type is specified class, or one of its subtypes.
|
BasicPolymorphicTypeValidator.Builder |
allowIfBaseType(Pattern patternForBase)
Method for appending matcher that will allow all subtypes in cases where
nominal base type's class name matches given
Pattern
For example, call to |
BasicPolymorphicTypeValidator.Builder |
allowIfBaseType(String prefixForBase)
Method for appending matcher that will allow all subtypes in cases where
nominal base type's class name starts with specific prefix.
|
BasicPolymorphicTypeValidator.Builder |
allowIfSubType(BasicPolymorphicTypeValidator.TypeMatcher matcher)
Method for appending custom matcher called with resolved subtype: if matcher returns
true , type will be accepted; if false , other
matchers are applied. |
BasicPolymorphicTypeValidator.Builder |
allowIfSubType(Class<?> subTypeBase)
Method for appending matcher that will allow specific subtype (regardless
of declared base type) if it is
subTypeBase or its subtype. |
BasicPolymorphicTypeValidator.Builder |
allowIfSubType(Pattern patternForSubType)
Method for appending matcher that will allow specific subtype (regardless
of declared base type) in cases where subclass name matches given
Pattern . |
BasicPolymorphicTypeValidator.Builder |
allowIfSubType(String prefixForSubType)
Method for appending matcher that will allow specific subtype (regardless
of declared base type)
in cases where subclass name starts with specified prefix
For example, call to
|
BasicPolymorphicTypeValidator.Builder |
allowIfSubTypeIsArray()
Method for appending matcher that will allow all subtypes that are Java arrays
(regardless of element type).
|
BasicPolymorphicTypeValidator |
build() |
BasicPolymorphicTypeValidator.Builder |
denyForExactBaseType(Class<?> baseTypeToDeny)
Method for appending matcher that will mark any polymorphic properties with exact
specific class to be invalid.
|
protected Set<Class<?>> _invalidBaseTypes
Object
or Serializable
.protected List<BasicPolymorphicTypeValidator.TypeMatcher> _baseTypeMatchers
protected List<BasicPolymorphicTypeValidator.NameMatcher> _subTypeNameMatchers
protected List<BasicPolymorphicTypeValidator.TypeMatcher> _subTypeClassMatchers
public BasicPolymorphicTypeValidator.Builder allowIfBaseType(Class<?> baseOfBase)
builder.allowIfBaseType(MyBaseType.class)would indicate that any polymorphic properties where declared base type is
MyBaseType
(or subclass thereof) would allow all legal (assignment-compatible)
subtypes.public BasicPolymorphicTypeValidator.Builder allowIfBaseType(Pattern patternForBase)
Pattern
For example, call to
builder.allowIfBaseType(Pattern.compile("com\\.mycompany\\..*")would indicate that any polymorphic properties where declared base type is in package
com.mycompany
would allow all legal (assignment-compatible)
subtypes.
NOTE! Pattern
match is applied using
if (patternForBase.matcher(typeId).matches()) { }
that is, it must match the whole class name, not just part.
public BasicPolymorphicTypeValidator.Builder allowIfBaseType(String prefixForBase)
builder.allowIfBaseType("com.mycompany.")would indicate that any polymorphic properties where declared base type is in package
com.mycompany
would allow all legal (assignment-compatible)
subtypes.public BasicPolymorphicTypeValidator.Builder allowIfBaseType(BasicPolymorphicTypeValidator.TypeMatcher matcher)
true
, all possible subtypes will be accepted; if false
, other
matchers are applied.matcher
- Custom matcher to apply to base typepublic BasicPolymorphicTypeValidator.Builder denyForExactBaseType(Class<?> baseTypeToDeny)
builder.denyforExactBaseType(Object.class)would indicate that any polymorphic properties where declared base type is
java.lang.Object
would be deemed invalid, and attempt to deserialize values of such types
should result in an exception.public BasicPolymorphicTypeValidator.Builder allowIfSubType(Class<?> subTypeBase)
subTypeBase
or its subtype.
For example, call to
builder.allowIfSubType(MyImplType.class)would indicate that any polymorphic values with type of is
MyImplType
(or subclass thereof)
would be allowed.public BasicPolymorphicTypeValidator.Builder allowIfSubType(Pattern patternForSubType)
Pattern
.
For example, call to
builder.allowIfSubType(Pattern.compile("com\\.mycompany\\.")would indicate that any polymorphic values in package
com.mycompany
would be allowed.
NOTE! Pattern
match is applied using
if (patternForSubType.matcher(typeId).matches()) { }
that is, it must match the whole class name, not just part.
public BasicPolymorphicTypeValidator.Builder allowIfSubType(String prefixForSubType)
builder.allowIfSubType("com.mycompany.")would indicate that any polymorphic values in package
com.mycompany
would be allowed.public BasicPolymorphicTypeValidator.Builder allowIfSubType(BasicPolymorphicTypeValidator.TypeMatcher matcher)
true
, type will be accepted; if false
, other
matchers are applied.matcher
- Custom matcher to apply to resolved subtypepublic BasicPolymorphicTypeValidator.Builder allowIfSubTypeIsArray()
@JsonTypeInfo
) use case (since annotation only applies to element
types, not container).
NOTE: not used with other Java collection types (List
s,
Collection
s), mostly since use of generic types as polymorphic
values is not (well) supported.
public BasicPolymorphicTypeValidator build()
protected BasicPolymorphicTypeValidator.Builder _appendBaseMatcher(BasicPolymorphicTypeValidator.TypeMatcher matcher)
protected BasicPolymorphicTypeValidator.Builder _appendSubNameMatcher(BasicPolymorphicTypeValidator.NameMatcher matcher)
protected BasicPolymorphicTypeValidator.Builder _appendSubClassMatcher(BasicPolymorphicTypeValidator.TypeMatcher matcher)
Copyright © 2008–2020 FasterXML. All rights reserved.