Package com.fasterxml.jackson.databind
Class DatabindContext
- java.lang.Object
-
- com.fasterxml.jackson.databind.DatabindContext
-
- Direct Known Subclasses:
DeserializationContext
,SerializerProvider
public abstract class DatabindContext extends Object
Shared base class forDeserializationContext
andSerializerProvider
, context objects passed through data-binding process. Designed so that some of implementations can rely on shared aspects like access to secondary contextual objects like type factories or handler instantiators.- Since:
- 2.2
-
-
Constructor Summary
Constructors Constructor Description DatabindContext()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract boolean
canOverrideAccessModifiers()
Convenience method for accessing serialization view in use (if any); equivalent to:abstract JavaType
constructSpecializedType(JavaType baseType, Class<?> subclass)
Convenience method for constructing subtypes, retaining generic type parameter (if any).JavaType
constructType(Type type)
Converter<Object,Object>
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 Class<?>
getActiveView()
Accessor for locating currently active view, if any; returns null if no view has been set.abstract AnnotationIntrospector
getAnnotationIntrospector()
Convenience method for accessing serialization view in use (if any); equivalent to:abstract Object
getAttribute(Object key)
Method for accessing attributes available in this context.abstract MapperConfig<?>
getConfig()
Accessor to currently active configuration (both per-request configs and per-mapper config).abstract JsonFormat.Value
getDefaultPropertyFormat(Class<?> baseType)
abstract Locale
getLocale()
abstract TimeZone
getTimeZone()
abstract TypeFactory
getTypeFactory()
abstract boolean
isEnabled(MapperFeature feature)
Convenience method for checking whether specified serialization feature is enabled or not.ObjectIdGenerator<?>
objectIdGeneratorInstance(Annotated annotated, ObjectIdInfo objectIdInfo)
ObjectIdResolver
objectIdResolverInstance(Annotated annotated, ObjectIdInfo objectIdInfo)
abstract <T> T
reportBadDefinition(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> T
reportBadDefinition(Class<?> type, String msg)
JavaType
resolveAndValidateSubType(JavaType baseType, String subClass, PolymorphicTypeValidator ptv)
Lookup method similar toresolveSubType(com.fasterxml.jackson.databind.JavaType, java.lang.String)
but one that also validates that resulting subtype is valid according to givenPolymorphicTypeValidator
.JavaType
resolveSubType(JavaType baseType, String subClassName)
Lookup method called when code needs to resolve class name from input; usually simple lookup.abstract DatabindContext
setAttribute(Object key, Object value)
Method for setting per-call value of given attribute.
-
-
-
Method Detail
-
getConfig
public abstract MapperConfig<?> getConfig()
Accessor to currently active configuration (both per-request configs and per-mapper config).
-
getAnnotationIntrospector
public abstract AnnotationIntrospector getAnnotationIntrospector()
Convenience method for accessing serialization view in use (if any); equivalent to:getConfig().getAnnotationIntrospector();
-
isEnabled
public abstract boolean isEnabled(MapperFeature feature)
Convenience method for checking whether specified serialization feature is enabled or not. Shortcut for:getConfig().isEnabled(feature);
-
canOverrideAccessModifiers
public abstract boolean canOverrideAccessModifiers()
Convenience method for accessing serialization view in use (if any); equivalent to:getConfig().canOverrideAccessModifiers();
-
getActiveView
public abstract Class<?> getActiveView()
Accessor for locating currently active view, if any; returns null if no view has been set.
-
getLocale
public abstract Locale getLocale()
- Since:
- 2.6
-
getTimeZone
public abstract TimeZone getTimeZone()
- Since:
- 2.6
-
getDefaultPropertyFormat
public abstract JsonFormat.Value getDefaultPropertyFormat(Class<?> baseType)
- Since:
- 2.7
-
getAttribute
public abstract Object getAttribute(Object key)
Method for accessing attributes available in this context. Per-call attributes have highest precedence; attributes set viaObjectReader
orObjectWriter
have lower precedence.- Parameters:
key
- Key of the attribute to get- Returns:
- Value of the attribute, if any; null otherwise
- Since:
- 2.3
-
setAttribute
public abstract DatabindContext setAttribute(Object key, Object value)
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
- Since:
- 2.3
-
constructSpecializedType
public abstract JavaType constructSpecializedType(JavaType baseType, Class<?> subclass)
Convenience method for constructing subtypes, retaining generic type parameter (if any).Note: since 2.11 handling has varied a bit across serialization, deserialization.
-
resolveSubType
public JavaType resolveSubType(JavaType baseType, String subClassName) throws JsonMappingException
Lookup method called when code needs to resolve class name from input; usually simple lookup. Note that unlikeresolveAndValidateSubType(com.fasterxml.jackson.databind.JavaType, java.lang.String, com.fasterxml.jackson.databind.jsontype.PolymorphicTypeValidator)
this method DOES NOT validate subtype against configuredPolymorphicTypeValidator
: usually because such check has already been made.- Throws:
JsonMappingException
- Since:
- 2.9
-
resolveAndValidateSubType
public JavaType resolveAndValidateSubType(JavaType baseType, String subClass, PolymorphicTypeValidator ptv) throws JsonMappingException
Lookup method similar toresolveSubType(com.fasterxml.jackson.databind.JavaType, java.lang.String)
but one that also validates that resulting subtype is valid according to givenPolymorphicTypeValidator
.- Throws:
JsonMappingException
- Since:
- 2.10
-
getTypeFactory
public abstract TypeFactory getTypeFactory()
-
objectIdGeneratorInstance
public ObjectIdGenerator<?> objectIdGeneratorInstance(Annotated annotated, ObjectIdInfo objectIdInfo) throws JsonMappingException
- Throws:
JsonMappingException
-
objectIdResolverInstance
public ObjectIdResolver objectIdResolverInstance(Annotated annotated, ObjectIdInfo objectIdInfo)
-
converterInstance
public Converter<Object,Object> converterInstance(Annotated annotated, Object converterDef) throws JsonMappingException
Helper method to use to construct aConverter
, given a definition that may be either actual converter instance, or Class for instantiating one.- Throws:
JsonMappingException
- Since:
- 2.2
-
reportBadDefinition
public abstract <T> T reportBadDefinition(JavaType type, String msg) throws JsonMappingException
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:
JsonMappingException
- Since:
- 2.9
-
reportBadDefinition
public <T> T reportBadDefinition(Class<?> type, String msg) throws JsonMappingException
- Throws:
JsonMappingException
- Since:
- 2.9
-
-