Class DatabindContext
java.lang.Object
tools.jackson.databind.DatabindContext
- Direct Known Subclasses:
DeserializationContext, SerializationContext
Shared base class for
DeserializationContext and
SerializationContext, context objects passed through data-binding
process. Designed so that some of the implementations can rely on shared
aspects like access to secondary contextual objects like type factories
or handler instantiators.-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final intLet's limit length of error messages, for cases where underlying data may be very large -- no point in spamming logs with megabytes of meaningless data. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected String_colonConcat(String msgBase, String extra) protected Stringprotected final Stringprotected String_quotedString(String desc) private JavaType_resolveAndValidateGeneric(JavaType baseType, String subClass, PolymorphicTypeValidator ptv, int ltIndex) protected <T> T_throwNotASubtype(JavaType baseType, String subType) protected <T> T_throwSubtypeClassNotAllowed(JavaType baseType, String subType, PolymorphicTypeValidator ptv) protected <T> T_throwSubtypeNameNotAllowed(JavaType baseType, String subType, PolymorphicTypeValidator ptv) protected final Stringabstract booleanConvenience method for accessing serialization view in use (if any); equivalent to:protected abstract ClassIntrospectorabstract JavaTypeconstructSpecializedType(JavaType baseType, Class<?> subclass) Convenience method for constructing subtypes, retaining generic type parameter (if any).constructType(Type type) converterInstance(Annotated annotated, Object converterDef) Helper method to use to construct aConverter, given a definition that may be either actual converter instance, or Class for instantiating one.abstract PropertyNamefindRootName(Class<?> rawRootType) abstract PropertyNamefindRootName(JavaType rootType) abstract Class<?> Accessor for locating currently active view, if any; returns null if no view has been set.abstract AnnotationIntrospectorConvenience method for accessing serialization view in use (if any); equivalent to:abstract ObjectgetAttribute(Object key) Method for accessing attributes available in this context.abstract MapperConfig<?> Accessor to currently active configuration (both per-request configs and per-mapper config).abstract DatatypeFeaturesabstract com.fasterxml.jackson.annotation.JsonFormat.ValuegetDefaultPropertyFormat(Class<?> baseType) abstract Localeabstract TimeZoneabstract TypeFactoryfinal BeanDescriptionConvenience method for doing full "for serialization or deserialization" introspection of specified type; results may be cached for duration (lifespan) of this context as well.abstract BeanDescriptionintrospectBeanDescription(JavaType type, AnnotatedClass classDef) introspectClassAnnotations(Class<?> rawType) protected abstract DatabindExceptioninvalidTypeIdException(JavaType baseType, String typeId, String extraDesc) Helper method for constructing exception to indicate that given type id could not be resolved to a valid subtype of specified base type.final booleanabstract booleanisEnabled(DatatypeFeature feature) Method for checking whether specified datatype feature is enabled or not.abstract booleanisEnabled(MapperFeature feature) Convenience method for checking whether specified Mapper feature is enabled or not.com.fasterxml.jackson.annotation.ObjectIdGenerator<?> objectIdGeneratorInstance(Annotated annotated, ObjectIdInfo objectIdInfo) com.fasterxml.jackson.annotation.ObjectIdResolverobjectIdResolverInstance(Annotated annotated, ObjectIdInfo objectIdInfo) <T> TreportBadDefinition(Class<?> type, String msg) abstract <T> TreportBadDefinition(JavaType type, String msg) Helper method called to indicate a generic problem that stems from type definition(s), not input data, or input/output state; typically this means throwing aInvalidDefinitionException.<T> TreportBadTypeDefinition(BeanDescription.Supplier beanDescRef, String msg, Object... msgArgs) abstract <T> TreportBadTypeDefinition(BeanDescription bean, String msg, Object... msgArgs) resolveAndValidateSubType(JavaType baseType, String subClass, PolymorphicTypeValidator ptv) Lookup method similar toresolveSubType(JavaType, String)but one that also validates that resulting subtype is valid according to givenPolymorphicTypeValidator.resolveSubType(JavaType baseType, String subClassName) Lookup method called when code needs to resolve class name from input; usually simple lookup.abstract DatabindContextsetAttribute(Object key, Object value) Method for setting per-call value of given attribute.
-
Field Details
-
MAX_ERROR_STR_LEN
private static final int MAX_ERROR_STR_LENLet's limit length of error messages, for cases where underlying data may be very large -- no point in spamming logs with megabytes of meaningless data.- See Also:
-
-
Constructor Details
-
DatabindContext
public DatabindContext()
-
-
Method Details
-
getConfig
Accessor to currently active configuration (both per-request configs and per-mapper config). -
getAnnotationIntrospector
Convenience method for accessing serialization view in use (if any); equivalent to:getConfig().getAnnotationIntrospector();
-
isEnabled
Convenience method for checking whether specified Mapper feature is enabled or not. Shortcut for:getConfig().isEnabled(feature);
-
isAnnotationProcessingEnabled
public final boolean isAnnotationProcessingEnabled() -
isEnabled
Method for checking whether specified datatype feature is enabled or not.- Since:
- 2.14
-
getDatatypeFeatures
- Since:
- 2.15
-
canOverrideAccessModifiers
public abstract boolean canOverrideAccessModifiers()Convenience method for accessing serialization view in use (if any); equivalent to:getConfig().canOverrideAccessModifiers();
-
getActiveView
Accessor for locating currently active view, if any; returns null if no view has been set. -
getLocale
-
getTimeZone
-
getDefaultPropertyFormat
public abstract com.fasterxml.jackson.annotation.JsonFormat.Value getDefaultPropertyFormat(Class<?> baseType) -
getAttribute
Method for accessing attributes available in this context. Per-call attributes have highest precedence; attributes set viaObjectReaderorObjectWriterhave lower precedence.- Parameters:
key- Key of the attribute to get- Returns:
- Value of the attribute, if any; null otherwise
-
setAttribute
Method for setting per-call value of given attribute. This will override any previously defined value for the attribute within this context.- Parameters:
key- Key of the attribute to setvalue- Value to set attribute to- Returns:
- This context object, to allow chaining
-
constructType
-
constructSpecializedType
-
resolveSubType
Lookup method called when code needs to resolve class name from input; usually simple lookup. Note that unlikeresolveAndValidateSubType(JavaType, String, PolymorphicTypeValidator)this method DOES NOT validate subtype against configuredPolymorphicTypeValidator: usually because such check has already been made. -
resolveAndValidateSubType
public JavaType resolveAndValidateSubType(JavaType baseType, String subClass, PolymorphicTypeValidator ptv) Lookup method similar toresolveSubType(JavaType, String)but one that also validates that resulting subtype is valid according to givenPolymorphicTypeValidator. -
_resolveAndValidateGeneric
private JavaType _resolveAndValidateGeneric(JavaType baseType, String subClass, PolymorphicTypeValidator ptv, int ltIndex) -
_throwNotASubtype
- Throws:
DatabindException
-
_throwSubtypeNameNotAllowed
protected <T> T _throwSubtypeNameNotAllowed(JavaType baseType, String subType, PolymorphicTypeValidator ptv) throws DatabindException - Throws:
DatabindException
-
_throwSubtypeClassNotAllowed
protected <T> T _throwSubtypeClassNotAllowed(JavaType baseType, String subType, PolymorphicTypeValidator ptv) throws DatabindException - Throws:
DatabindException
-
invalidTypeIdException
protected abstract DatabindException invalidTypeIdException(JavaType baseType, String typeId, String extraDesc) Helper method for constructing exception to indicate that given type id could not be resolved to a valid subtype of specified base type. Most commonly called during polymorphic deserialization.Note that most of the time this method should NOT be called directly: instead, method
handleUnknownTypeId()should be called which will call this method if necessary. -
getTypeFactory
-
introspectBeanDescription
Convenience method for doing full "for serialization or deserialization" introspection of specified type; results may be cached for duration (lifespan) of this context as well. -
introspectBeanDescription
-
lazyIntrospectBeanDescription
-
introspectClassAnnotations
-
introspectDirectClassAnnotations
-
introspectClassAnnotations
-
classIntrospector
-
objectIdGeneratorInstance
public com.fasterxml.jackson.annotation.ObjectIdGenerator<?> objectIdGeneratorInstance(Annotated annotated, ObjectIdInfo objectIdInfo) -
objectIdResolverInstance
public com.fasterxml.jackson.annotation.ObjectIdResolver objectIdResolverInstance(Annotated annotated, ObjectIdInfo objectIdInfo) -
converterInstance
-
findRootName
-
findRootName
-
reportBadDefinition
Helper method called to indicate a generic problem that stems from type definition(s), not input data, or input/output state; typically this means throwing aInvalidDefinitionException.- Throws:
DatabindException
-
reportBadDefinition
- Throws:
DatabindException
-
reportBadTypeDefinition
public abstract <T> T reportBadTypeDefinition(BeanDescription bean, String msg, Object... msgArgs) throws DatabindException - Throws:
DatabindException
-
reportBadTypeDefinition
public <T> T reportBadTypeDefinition(BeanDescription.Supplier beanDescRef, String msg, Object... msgArgs) throws DatabindException - Throws:
DatabindException
-
_format
-
_truncate
-
_quotedString
-
_colonConcat
-
_desc
-