Class BasicPolymorphicTypeValidator.Builder
- java.lang.Object
-
- com.fasterxml.jackson.databind.jsontype.BasicPolymorphicTypeValidator.Builder
-
- Enclosing class:
- BasicPolymorphicTypeValidator
public static class BasicPolymorphicTypeValidator.Builder extends java.lang.Object
Builder class for configuring and constructing immutableBasicPolymorphicTypeValidator
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
orPolymorphicTypeValidator.Validity.DENIED
) is used and no further rules are checked.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description BasicPolymorphicTypeValidator.Builder
allowIfBaseType(BasicPolymorphicTypeValidator.TypeMatcher matcher)
Method for appending custom matcher called with base type: if matcher returnstrue
, all possible subtypes will be accepted; iffalse
, other matchers are applied.BasicPolymorphicTypeValidator.Builder
allowIfBaseType(java.lang.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(java.lang.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
allowIfBaseType(java.util.regex.Pattern patternForBase)
Method for appending matcher that will allow all subtypes in cases where nominal base type's class name matches givenPattern
For example, call toBasicPolymorphicTypeValidator.Builder
allowIfSubType(BasicPolymorphicTypeValidator.TypeMatcher matcher)
Method for appending custom matcher called with resolved subtype: if matcher returnstrue
, type will be accepted; iffalse
, other matchers are applied.BasicPolymorphicTypeValidator.Builder
allowIfSubType(java.lang.Class<?> subTypeBase)
Method for appending matcher that will allow specific subtype (regardless of declared base type) if it issubTypeBase
or its subtype.BasicPolymorphicTypeValidator.Builder
allowIfSubType(java.lang.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 toBasicPolymorphicTypeValidator.Builder
allowIfSubType(java.util.regex.Pattern patternForSubType)
Method for appending matcher that will allow specific subtype (regardless of declared base type) in cases where subclass name matches givenPattern
.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(java.lang.Class<?> baseTypeToDeny)
Method for appending matcher that will mark any polymorphic properties with exact specific class to be invalid.
-
-
-
Method Detail
-
allowIfBaseType
public BasicPolymorphicTypeValidator.Builder allowIfBaseType(java.lang.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. For example, call tobuilder.allowIfBaseType(MyBaseType.class)
would indicate that any polymorphic properties where declared base type isMyBaseType
(or subclass thereof) would allow all legal (assignment-compatible) subtypes.
-
allowIfBaseType
public BasicPolymorphicTypeValidator.Builder allowIfBaseType(java.util.regex.Pattern patternForBase)
Method for appending matcher that will allow all subtypes in cases where nominal base type's class name matches givenPattern
For example, call tobuilder.allowIfBaseType(Pattern.compile("com\\.mycompany\\..*")
would indicate that any polymorphic properties where declared base type is in packagecom.mycompany
would allow all legal (assignment-compatible) subtypes.NOTE!
Pattern
match is applied usingif (patternForBase.matcher(typeId).matches()) { }
that is, it must match the whole class name, not just part.
-
allowIfBaseType
public BasicPolymorphicTypeValidator.Builder allowIfBaseType(java.lang.String prefixForBase)
Method for appending matcher that will allow all subtypes in cases where nominal base type's class name starts with specific prefix. For example, call tobuilder.allowIfBaseType("com.mycompany.")
would indicate that any polymorphic properties where declared base type is in packagecom.mycompany
would allow all legal (assignment-compatible) subtypes.
-
allowIfBaseType
public BasicPolymorphicTypeValidator.Builder allowIfBaseType(BasicPolymorphicTypeValidator.TypeMatcher matcher)
Method for appending custom matcher called with base type: if matcher returnstrue
, all possible subtypes will be accepted; iffalse
, other matchers are applied.- Parameters:
matcher
- Custom matcher to apply to base type- Returns:
- This Builder to allow call chaining
- Since:
- 2.11
-
denyForExactBaseType
public BasicPolymorphicTypeValidator.Builder denyForExactBaseType(java.lang.Class<?> baseTypeToDeny)
Method for appending matcher that will mark any polymorphic properties with exact specific class to be invalid. For example, call tobuilder.denyforExactBaseType(Object.class)
would indicate that any polymorphic properties where declared base type isjava.lang.Object
would be deemed invalid, and attempt to deserialize values of such types should result in an exception.
-
allowIfSubType
public BasicPolymorphicTypeValidator.Builder allowIfSubType(java.lang.Class<?> subTypeBase)
Method for appending matcher that will allow specific subtype (regardless of declared base type) if it issubTypeBase
or its subtype. For example, call tobuilder.allowIfSubType(MyImplType.class)
would indicate that any polymorphic values with type of isMyImplType
(or subclass thereof) would be allowed.
-
allowIfSubType
public BasicPolymorphicTypeValidator.Builder allowIfSubType(java.util.regex.Pattern patternForSubType)
Method for appending matcher that will allow specific subtype (regardless of declared base type) in cases where subclass name matches givenPattern
. For example, call tobuilder.allowIfSubType(Pattern.compile("com\\.mycompany\\.")
would indicate that any polymorphic values in packagecom.mycompany
would be allowed.NOTE!
Pattern
match is applied usingif (patternForSubType.matcher(typeId).matches()) { }
that is, it must match the whole class name, not just part.
-
allowIfSubType
public BasicPolymorphicTypeValidator.Builder allowIfSubType(java.lang.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 tobuilder.allowIfSubType("com.mycompany.")
would indicate that any polymorphic values in packagecom.mycompany
would be allowed.
-
allowIfSubType
public BasicPolymorphicTypeValidator.Builder allowIfSubType(BasicPolymorphicTypeValidator.TypeMatcher matcher)
Method for appending custom matcher called with resolved subtype: if matcher returnstrue
, type will be accepted; iffalse
, other matchers are applied.- Parameters:
matcher
- Custom matcher to apply to resolved subtype- Returns:
- This Builder to allow call chaining
- Since:
- 2.11
-
allowIfSubTypeIsArray
public BasicPolymorphicTypeValidator.Builder allowIfSubTypeIsArray()
Method for appending matcher that will allow all subtypes that are Java arrays (regardless of element type). Note that this does NOT validate element type itself as long as Polymorphic Type handling is enabled for element type: this is the case with all standard "Default Typing" inclusion criteria as well as for annotation (@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.- Since:
- 2.11
-
build
public BasicPolymorphicTypeValidator build()
-
-