Class DatabindContext

java.lang.Object
tools.jackson.databind.DatabindContext
Direct Known Subclasses:
DeserializationContext, SerializationContext

public abstract class DatabindContext extends Object
Shared base class for DeserializationContext and SerializationContext, 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.
  • Constructor Details

    • DatabindContext

      public DatabindContext()
  • Method Details

    • 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 Mapper feature is enabled or not. Shortcut for:
        getConfig().isEnabled(feature);
      
    • isAnnotationProcessingEnabled

      public final boolean isAnnotationProcessingEnabled()
    • isEnabled

      public abstract boolean isEnabled(DatatypeFeature feature)
      Method for checking whether specified datatype feature is enabled or not.
      Since:
      2.14
    • getDatatypeFeatures

      public abstract DatatypeFeatures getDatatypeFeatures()
      Since:
      2.15
    • 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()
    • getTimeZone

      public abstract TimeZone getTimeZone()
    • getDefaultPropertyFormat

      public abstract JsonFormat.Value getDefaultPropertyFormat(Class<?> baseType)
    • getAttribute

      public abstract Object getAttribute(Object key)
      Method for accessing attributes available in this context. Per-call attributes have highest precedence; attributes set via ObjectReader or ObjectWriter have lower precedence.
      Parameters:
      key - Key of the attribute to get
      Returns:
      Value of the attribute, if any; null otherwise
    • 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 set
      value - Value to set attribute to
      Returns:
      This context object, to allow chaining
    • constructType

      public JavaType constructType(Type type)
      Convenience method for constructing JavaType for given JDK type (usually Class)
    • 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)
      Lookup method called when code needs to resolve class name from input; usually simple lookup. Note that unlike resolveAndValidateSubType(tools.jackson.databind.JavaType, java.lang.String, tools.jackson.databind.jsontype.PolymorphicTypeValidator) this method DOES NOT validate subtype against configured PolymorphicTypeValidator: usually because such check has already been made.
    • resolveAndValidateSubType

      public JavaType resolveAndValidateSubType(JavaType baseType, String subClass, PolymorphicTypeValidator ptv)
      Lookup method similar to resolveSubType(tools.jackson.databind.JavaType, java.lang.String) but one that also validates that resulting subtype is valid according to given PolymorphicTypeValidator.
    • _throwNotASubtype

      protected <T> T _throwNotASubtype(JavaType baseType, String subType) throws DatabindException
      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

      public abstract TypeFactory getTypeFactory()
    • introspectBeanDescription

      public final BeanDescription introspectBeanDescription(JavaType type)
      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

      public abstract BeanDescription introspectBeanDescription(JavaType type, AnnotatedClass classDef)
    • lazyIntrospectBeanDescription

      public BeanDescription.Supplier lazyIntrospectBeanDescription(JavaType type)
    • introspectClassAnnotations

      public AnnotatedClass introspectClassAnnotations(JavaType type)
    • introspectDirectClassAnnotations

      public AnnotatedClass introspectDirectClassAnnotations(JavaType type)
    • introspectClassAnnotations

      public AnnotatedClass introspectClassAnnotations(Class<?> rawType)
    • classIntrospector

      protected abstract ClassIntrospector classIntrospector()
    • objectIdGeneratorInstance

      public ObjectIdGenerator<?> objectIdGeneratorInstance(Annotated annotated, ObjectIdInfo objectIdInfo)
    • objectIdResolverInstance

      public ObjectIdResolver objectIdResolverInstance(Annotated annotated, ObjectIdInfo objectIdInfo)
    • converterInstance

      public Converter<Object,Object> converterInstance(Annotated annotated, Object converterDef)
      Helper method to use to construct a Converter, given a definition that may be either actual converter instance, or Class for instantiating one.
    • findRootName

      public abstract PropertyName findRootName(JavaType rootType)
    • findRootName

      public abstract PropertyName findRootName(Class<?> rawRootType)
    • reportBadDefinition

      public abstract <T> T reportBadDefinition(JavaType type, String msg) throws DatabindException
      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 a InvalidDefinitionException.
      Throws:
      DatabindException
    • reportBadDefinition

      public <T> T reportBadDefinition(Class<?> type, String msg) throws DatabindException
      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

      protected final String _format(String msg, Object... msgArgs)
    • _truncate

      protected final String _truncate(String desc)
    • _quotedString

      protected String _quotedString(String desc)
    • _colonConcat

      protected String _colonConcat(String msgBase, String extra)
    • _desc

      protected String _desc(String desc)