Module tools.jackson.databind
Class StdTypeResolverBuilder
java.lang.Object
tools.jackson.databind.jsontype.impl.StdTypeResolverBuilder
- All Implemented Interfaces:
TypeResolverBuilder<StdTypeResolverBuilder>
- Direct Known Subclasses:
DefaultTypeResolverBuilder
public class StdTypeResolverBuilder
extends Object
implements TypeResolverBuilder<StdTypeResolverBuilder>
Default
TypeResolverBuilder implementation.-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected TypeIdResolverprotected Class<?>Default class to use in case type information is not available or is broken.protected JsonTypeInfo.Idprotected JsonTypeInfo.Asprotected BooleanBoolean value configured throughJsonTypeInfo.requireTypeIdForSubtypes().protected booleanWhether type id should be exposed to deserializers or notprotected String -
Constructor Summary
ConstructorsModifierConstructorDescriptionStdTypeResolverBuilder(JsonTypeInfo.Id idType, JsonTypeInfo.As idAs, String propName) StdTypeResolverBuilder(JsonTypeInfo.Value settings) protectedStdTypeResolverBuilder(StdTypeResolverBuilder base, Class<?> defaultImpl) -
Method Summary
Modifier and TypeMethodDescriptionprotected boolean_hasTypeResolver(DatabindContext ctxt, JavaType baseType) Checks whether the given class has annotations indicating some type resolver is applied, for exampleJsonTypeInfo.protected String_propName(String propName, JsonTypeInfo.Id idType) protected boolean_strictTypeIdHandling(DatabindContext ctxt, JavaType baseType) Determines whether strict type ID handling should be used for this type or not.protected booleanallowPrimitiveTypes(DatabindContext ctxt, JavaType baseType) Overridable helper method that is called to determine whether type serializers and type deserializers may be created even if base type is Javaprimitivetype.buildTypeDeserializer(DeserializationContext ctxt, JavaType baseType, Collection<NamedType> subtypes) Method for building type deserializer based on current configuration of this builder.buildTypeSerializer(SerializationContext ctxt, JavaType baseType, Collection<NamedType> subtypes) Method for building type serializer based on current configuration of this builder.protected JavaTypedefineDefaultImpl(DatabindContext ctxt, 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 TypeIdResolveridResolver(DatabindContext ctxt, 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.init(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)booleanstatic StdTypeResolverBuilderprotected PolymorphicTypeValidatorreportInvalidBaseType(DatabindContext ctxt, JavaType baseType, PolymorphicTypeValidator ptv) Overridable helper method for determining actual validator to use when constructing type serializers and type deserializers.protected PolymorphicTypeValidatorverifyBaseTypeValidity(DatabindContext ctxt, 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 to use if type id is either not available, or cannot be resolved.withSettings(JsonTypeInfo.Value settings) Method for overriding type information.
-
Field Details
-
_idType
-
_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. -
_defaultImpl
Default class to use in case type information is not available or is broken. -
_customIdResolver
-
-
Constructor Details
-
StdTypeResolverBuilder
public StdTypeResolverBuilder() -
StdTypeResolverBuilder
-
StdTypeResolverBuilder
-
StdTypeResolverBuilder
-
-
Method Details
-
noTypeInfoBuilder
-
buildTypeSerializer
public TypeSerializer buildTypeSerializer(SerializationContext ctxt, JavaType baseType, Collection<NamedType> subtypes) Description copied from interface:TypeResolverBuilderMethod for building type serializer based on current configuration of this builder.- Specified by:
buildTypeSerializerin interfaceTypeResolverBuilder<StdTypeResolverBuilder>baseType- Base type that constructed resolver will handle; super type of all types it will be used for.
-
buildTypeDeserializer
public TypeDeserializer buildTypeDeserializer(DeserializationContext ctxt, JavaType baseType, Collection<NamedType> subtypes) Description copied from interface:TypeResolverBuilderMethod for building type deserializer based on current configuration of this builder.- Specified by:
buildTypeDeserializerin interfaceTypeResolverBuilder<StdTypeResolverBuilder>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
Description copied from interface:TypeResolverBuilderInitialization 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)- Specified by:
initin interfaceTypeResolverBuilder<StdTypeResolverBuilder>- Parameters:
settings- Configuration settings to apply.- Returns:
- Resulting builder instance (usually this builder, but not necessarily)
-
withDefaultImpl
Description copied from interface:TypeResolverBuilder"Mutant factory" method for creating a new instance with different default implementation to use if type id is either not available, or cannot be resolved.In Jackson 2.x there was instead method
defaultImpl()which was a mutator: this method MUST NOT change the underlying state.- Specified by:
withDefaultImplin interfaceTypeResolverBuilder<StdTypeResolverBuilder>- Returns:
- Either this instance (if nothing changed) or a new instance with different default implementation
-
withSettings
Description copied from interface:TypeResolverBuilderMethod for overriding type information.- Specified by:
withSettingsin interfaceTypeResolverBuilder<StdTypeResolverBuilder>
-
_propName
-
getDefaultImpl
Description copied from interface:TypeResolverBuilderAccessor for currently configured default type; implementation class that may be used in case no valid type information is available during type resolution- Specified by:
getDefaultImplin interfaceTypeResolverBuilder<StdTypeResolverBuilder>
-
getTypeProperty
-
isTypeIdVisible
public boolean isTypeIdVisible() -
idResolver
protected TypeIdResolver idResolver(DatabindContext ctxt, 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(). -
verifyBaseTypeValidity
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. -
reportInvalidBaseType
protected PolymorphicTypeValidator reportInvalidBaseType(DatabindContext ctxt, JavaType baseType, PolymorphicTypeValidator ptv) -
allowPrimitiveTypes
Overridable helper method that is called to determine whether type serializers and type deserializers may be created even if base type is Javaprimitivetype. Default implementation simply returnsfalse(since primitive types cannot be sub-classed, are never polymorphic) but custom implementations may change the logic for some special cases.- Parameters:
ctxt- Currently active contextbaseType- Primitive base type for property being handled- Returns:
- True if type (de)serializer may be created even if base type is Java
primitivetype; false if not
-
_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_SUBTYPESis enabled.- Parameters:
ctxt- Currently active contextbaseType- the base type to check for type resolver annotations- Returns:
trueif the class has type resolver annotations, or the strict handling feature is enabled,falseotherwise.
-
_hasTypeResolver
Checks whether the given class has annotations indicating some type resolver is applied, for exampleJsonTypeInfo. Only initializes_hasTypeResolver(tools.jackson.databind.DatabindContext, tools.jackson.databind.JavaType)once if its value is null.- Parameters:
ctxt- Currently active contextbaseType- the base type to check for type resolver annotations- Returns:
- true if the class has type resolver annotations, false otherwise
-