Class StdTypeResolverBuilder
java.lang.Object
com.fasterxml.jackson.databind.jsontype.impl.StdTypeResolverBuilder
- All Implemented Interfaces:
TypeResolverBuilder<StdTypeResolverBuilder>
- Direct Known Subclasses:
ObjectMapper.DefaultTypeResolverBuilder
public class StdTypeResolverBuilder
extends Object
implements TypeResolverBuilder<StdTypeResolverBuilder>
Default
TypeResolverBuilder
implementation.-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected TypeIdResolver
protected Class
<?> Default class to use in case type information is not available or is broken.protected com.fasterxml.jackson.annotation.JsonTypeInfo.Id
protected com.fasterxml.jackson.annotation.JsonTypeInfo.As
protected Boolean
Boolean value configured throughJsonTypeInfo.requireTypeIdForSubtypes()
.protected boolean
Whether type id should be exposed to deserializers or notprotected String
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
StdTypeResolverBuilder
(com.fasterxml.jackson.annotation.JsonTypeInfo.Id idType, com.fasterxml.jackson.annotation.JsonTypeInfo.As idAs, String propName) StdTypeResolverBuilder
(com.fasterxml.jackson.annotation.JsonTypeInfo.Value settings) protected
StdTypeResolverBuilder
(StdTypeResolverBuilder base, Class<?> defaultImpl) Copy-constructor -
Method Summary
Modifier and TypeMethodDescriptionprotected boolean
_hasTypeResolver
(DeserializationConfig config, JavaType baseType) Checks whether the given class has annotations indicating some type resolver is applied, for exampleJsonTypeInfo
.protected String
protected boolean
_strictTypeIdHandling
(DeserializationConfig config, JavaType baseType) Determines whether strict type ID handling should be used for this type or not.protected boolean
allowPrimitiveTypes
(MapperConfig<?> config, JavaType baseType) Overridable helper method that is called to determine whether type serializers and type deserializers may be created even if base type is Javaprimitive
type.buildTypeDeserializer
(DeserializationConfig config, JavaType baseType, Collection<NamedType> subtypes) Method for building type deserializer based on current configuration of this builder.buildTypeSerializer
(SerializationConfig config, JavaType baseType, Collection<NamedType> subtypes) Method for building type serializer based on current configuration of this builder.defaultImpl
(Class<?> defaultImpl) Method for specifying default implementation to use if type id is either not available, or cannot be resolved.protected JavaType
defineDefaultImpl
(DeserializationConfig config, JavaType baseType) Class
<?> Accessor for currently configured default type; implementation class that may be used in case no valid type information is available during type resolutionprotected TypeIdResolver
idResolver
(MapperConfig<?> config, JavaType baseType, PolymorphicTypeValidator subtypeValidator, Collection<NamedType> subtypes, boolean forSer, boolean forDeser) Helper method that will either return configured custom type id resolver, or construct a standard resolver given configuration.inclusion
(com.fasterxml.jackson.annotation.JsonTypeInfo.As includeAs) Method for specifying mechanism to use for including type metadata in JSON.init
(com.fasterxml.jackson.annotation.JsonTypeInfo.Id idType, TypeIdResolver idRes) Initialization method that is called right after constructing the builder instance.init
(com.fasterxml.jackson.annotation.JsonTypeInfo.Value settings, TypeIdResolver idRes) Initialization method that is called right after constructing the builder instance, in cases where information could not be passed directly (for example when instantiated for an annotation)boolean
static StdTypeResolverBuilder
protected PolymorphicTypeValidator
reportInvalidBaseType
(MapperConfig<?> config, JavaType baseType, PolymorphicTypeValidator ptv) subTypeValidator
(MapperConfig<?> config) Overridable helper method for determining actual validator to use when constructing type serializers and type deserializers.typeIdVisibility
(boolean isVisible) Method for specifying whether type id should be visible toJsonDeserializer
s or not.typeProperty
(String typeIdPropName) Method for constructing an instance with specified type property name (property name to use for type id when using "as-property" inclusion).protected PolymorphicTypeValidator
verifyBaseTypeValidity
(MapperConfig<?> config, JavaType baseType) Helper method called to check that base type is valid regarding possible constraints on basetype/subtype combinations allowed for polymorphic type handling.withDefaultImpl
(Class<?> defaultImpl) "Mutant factory" method for creating a new instance with different default implementation.withSettings
(com.fasterxml.jackson.annotation.JsonTypeInfo.Value settings) Method for overriding type information.
-
Field Details
-
_idType
protected com.fasterxml.jackson.annotation.JsonTypeInfo.Id _idType -
_includeAs
protected com.fasterxml.jackson.annotation.JsonTypeInfo.As _includeAs -
_typeProperty
-
_typeIdVisible
protected boolean _typeIdVisibleWhether type id should be exposed to deserializers or not -
_requireTypeIdForSubtypes
Boolean value configured throughJsonTypeInfo.requireTypeIdForSubtypes()
. If this value is notnull
, this value should override the global configuration ofMapperFeature.REQUIRE_TYPE_ID_FOR_SUBTYPES
.- Since:
- 2.16 (backported from Jackson 3.0)
-
_defaultImpl
Default class to use in case type information is not available or is broken. -
_customIdResolver
-
-
Constructor Details
-
StdTypeResolverBuilder
public StdTypeResolverBuilder() -
StdTypeResolverBuilder
protected StdTypeResolverBuilder(com.fasterxml.jackson.annotation.JsonTypeInfo.Id idType, com.fasterxml.jackson.annotation.JsonTypeInfo.As idAs, String propName) - Since:
- 2.9
-
StdTypeResolverBuilder
Copy-constructor- Since:
- 2.13
-
StdTypeResolverBuilder
public StdTypeResolverBuilder(com.fasterxml.jackson.annotation.JsonTypeInfo.Value settings) - Since:
- 2.16
-
-
Method Details
-
noTypeInfoBuilder
-
buildTypeSerializer
public TypeSerializer buildTypeSerializer(SerializationConfig config, JavaType baseType, Collection<NamedType> subtypes) Description copied from interface:TypeResolverBuilder
Method for building type serializer based on current configuration of this builder.- Specified by:
buildTypeSerializer
in interfaceTypeResolverBuilder<StdTypeResolverBuilder>
- Parameters:
baseType
- Base type that constructed resolver will handle; super type of all types it will be used for.
-
buildTypeDeserializer
public TypeDeserializer buildTypeDeserializer(DeserializationConfig config, JavaType baseType, Collection<NamedType> subtypes) Description copied from interface:TypeResolverBuilder
Method for building type deserializer based on current configuration of this builder.- Specified by:
buildTypeDeserializer
in interfaceTypeResolverBuilder<StdTypeResolverBuilder>
- Parameters:
baseType
- Base type that constructed resolver will handle; super type of all types it will be used for.subtypes
- Known subtypes of the base type.
-
defineDefaultImpl
-
init
public StdTypeResolverBuilder init(com.fasterxml.jackson.annotation.JsonTypeInfo.Id idType, TypeIdResolver idRes) Description copied from interface:TypeResolverBuilder
Initialization method that is called right after constructing the builder instance.- Specified by:
init
in interfaceTypeResolverBuilder<StdTypeResolverBuilder>
- Parameters:
idType
- Which type metadata is usedidRes
- (optional) Custom type id resolver used, if any- Returns:
- Resulting builder instance (usually this builder, but not necessarily)
-
init
public StdTypeResolverBuilder init(com.fasterxml.jackson.annotation.JsonTypeInfo.Value settings, TypeIdResolver idRes) Description copied from interface:TypeResolverBuilder
Initialization method that is called right after constructing the builder instance, in cases where information could not be passed directly (for example when instantiated for an annotation)NOTE: This method is abstract in Jackson 3.0, at the moment of writing.
- Specified by:
init
in interfaceTypeResolverBuilder<StdTypeResolverBuilder>
- Parameters:
settings
- Configuration settings to apply.- Returns:
- Resulting builder instance (usually this builder, but not necessarily)
-
inclusion
Description copied from interface:TypeResolverBuilder
Method for specifying mechanism to use for including type metadata in JSON. If not explicitly called, setting defaults toJsonTypeInfo.As.PROPERTY
.- Specified by:
inclusion
in interfaceTypeResolverBuilder<StdTypeResolverBuilder>
- Parameters:
includeAs
- Mechanism used for including type metadata in JSON- Returns:
- Resulting builder instance (usually this builder, but may be a newly constructed instance for immutable builders}
-
typeProperty
Method for constructing an instance with specified type property name (property name to use for type id when using "as-property" inclusion).- Specified by:
typeProperty
in interfaceTypeResolverBuilder<StdTypeResolverBuilder>
- Parameters:
typeIdPropName
- Name of JSON property to use for including type information- Returns:
- Resulting builder instance (usually this builder, but may be a newly constructed instance for immutable builders}
-
defaultImpl
Description copied from interface:TypeResolverBuilder
Method for specifying default implementation to use if type id is either not available, or cannot be resolved.- Specified by:
defaultImpl
in interfaceTypeResolverBuilder<StdTypeResolverBuilder>
- Returns:
- Resulting builder instance (usually this builder, but may be a newly constructed instance for immutable builders}
-
typeIdVisibility
Description copied from interface:TypeResolverBuilder
Method for specifying whether type id should be visible toJsonDeserializer
s or not.- Specified by:
typeIdVisibility
in interfaceTypeResolverBuilder<StdTypeResolverBuilder>
- Returns:
- Resulting builder instance (usually this builder, but may be a newly constructed instance for immutable builders}
-
withDefaultImpl
Description copied from interface:TypeResolverBuilder
"Mutant factory" method for creating a new instance with different default implementation.- Specified by:
withDefaultImpl
in interfaceTypeResolverBuilder<StdTypeResolverBuilder>
- Returns:
- Either this instance (if nothing changed) or a new instance with different default implementation
-
withSettings
public StdTypeResolverBuilder withSettings(com.fasterxml.jackson.annotation.JsonTypeInfo.Value settings) Description copied from interface:TypeResolverBuilder
Method for overriding type information.- Specified by:
withSettings
in interfaceTypeResolverBuilder<StdTypeResolverBuilder>
-
_propName
protected String _propName(String propName, com.fasterxml.jackson.annotation.JsonTypeInfo.Id idType) - Since:
- 2.16; non-static since 2.17
-
getDefaultImpl
Description copied from interface:TypeResolverBuilder
Accessor for currently configured default type; implementation class that may be used in case no valid type information is available during type resolution- Specified by:
getDefaultImpl
in interfaceTypeResolverBuilder<StdTypeResolverBuilder>
-
getTypeProperty
-
isTypeIdVisible
public boolean isTypeIdVisible() -
idResolver
protected TypeIdResolver idResolver(MapperConfig<?> config, JavaType baseType, PolymorphicTypeValidator subtypeValidator, Collection<NamedType> subtypes, boolean forSer, boolean forDeser) Helper method that will either return configured custom type id resolver, or construct a standard resolver given configuration. -
subTypeValidator
Overridable helper method for determining actual validator to use when constructing type serializers and type deserializers.Default implementation simply uses one configured and accessible using
MapperConfig.getPolymorphicTypeValidator()
.- Since:
- 2.10
-
verifyBaseTypeValidity
protected PolymorphicTypeValidator verifyBaseTypeValidity(MapperConfig<?> config, JavaType baseType) Helper method called to check that base type is valid regarding possible constraints on basetype/subtype combinations allowed for polymorphic type handling. Currently limits are verified for class name - based methods only.- Since:
- 2.10
-
reportInvalidBaseType
protected PolymorphicTypeValidator reportInvalidBaseType(MapperConfig<?> config, JavaType baseType, PolymorphicTypeValidator ptv) - Since:
- 2.10
-
allowPrimitiveTypes
Overridable helper method that is called to determine whether type serializers and type deserializers may be created even if base type is Javaprimitive
type. Default implementation simply returnsfalse
(since primitive types can not be sub-classed, are never polymorphic) but custom implementations may change the logic for some special cases.- Parameters:
config
- Currently active configurationbaseType
- Primitive base type for property being handled- Returns:
- True if type (de)serializer may be created even if base type is Java
primitive
type; false if not - Since:
- 2.11.1
-
_strictTypeIdHandling
Determines whether strict type ID handling should be used for this type or not. This will be enabld as configured byJsonTypeInfo.requireTypeIdForSubtypes()
unless its value isOptBoolean.DEFAULT
. In case the value ofJsonTypeInfo.requireTypeIdForSubtypes()
isOptBoolean.DEFAULT
, this will be enabled when either the type has type resolver annotations or ifMapperFeature.REQUIRE_TYPE_ID_FOR_SUBTYPES
is enabled.- Parameters:
config
- the deserialization configuration to usebaseType
- the base type to check for type resolver annotations- Returns:
true
if the class has type resolver annotations, or the strict handling feature is enabled,false
otherwise.- Since:
- 2.15
-
_hasTypeResolver
Checks whether the given class has annotations indicating some type resolver is applied, for exampleJsonTypeInfo
. Only initializes_hasTypeResolver(com.fasterxml.jackson.databind.DeserializationConfig, com.fasterxml.jackson.databind.JavaType)
once if its value is null.- Parameters:
config
- the deserialization configuration to usebaseType
- the base type to check for type resolver annotations- Returns:
- true if the class has type resolver annotations, false otherwise
- Since:
- 2.15, using
ai.findPolymorphicTypeInfo(config, ac)
since 2.16.
-