All Known Implementing Classes:
ClassNameIdResolver, MinimalClassNameIdResolver, TypeIdResolverBase, TypeNameIdResolver

public interface TypeIdResolver
Interface that defines standard API for converting types to type identifiers and vice versa. Used by type resolvers (TypeSerializer, TypeDeserializer) for converting between type and matching id; id is stored in JSON and needed for creating instances of proper subtypes when deserializing values.

NOTE: it is strongly recommended that developers always extend abstract base class TypeIdResolverBase instead of directly implementing this interface; this helps prevent breakage in case new methds need to be added in this interface (something we try to avoid doing; but which may be necessary in some cases).

  • Method Summary

    Modifier and Type
    Method
    Description
    Method called for error-reporting and diagnostics purposes.
    Accessor for mechanism that this resolver uses for determining type id from type.
    Method that can be called to figure out type id to use for instances of base type (declared type of property).
    Method called to serialize type of the type of given value as a String to include in serialized JSON content.
    idFromValueAndType(Object value, Class<?> suggestedType)
    Alternative method used for determining type from combination of value and type, using suggested type (that serializer provides) and possibly value of that type.
    void
    init(JavaType baseType)
    Method that will be called once before any type resolution calls; used to initialize instance with configuration.
    Method called to resolve type from given type identifier.
  • Method Details

    • init

      void init(JavaType baseType)
      Method that will be called once before any type resolution calls; used to initialize instance with configuration. This is necessary since instances may be created via reflection, without ability to call specific constructor to pass in configuration settings.
      Parameters:
      baseType - Base type for which this id resolver instance is used
    • idFromValue

      String idFromValue(Object value)
      Method called to serialize type of the type of given value as a String to include in serialized JSON content.
    • idFromValueAndType

      String idFromValueAndType(Object value, Class<?> suggestedType)
      Alternative method used for determining type from combination of value and type, using suggested type (that serializer provides) and possibly value of that type. Most common implementation will use suggested type as is.
    • idFromBaseType

      String idFromBaseType()
      Method that can be called to figure out type id to use for instances of base type (declared type of property). This is usually only used for fallback handling, for cases where real type information is not available for some reason.
    • typeFromId

      JavaType typeFromId(DatabindContext context, String id) throws IOException
      Method called to resolve type from given type identifier.
      Throws:
      IOException
      Since:
      2.5 (throws clause added in 2.8)
    • getDescForKnownTypeIds

      String getDescForKnownTypeIds()
      Method called for error-reporting and diagnostics purposes.
      Since:
      2.7 -- but since 2.5 has existed in TypeIdResolverBase
    • getMechanism

      JsonTypeInfo.Id getMechanism()
      Accessor for mechanism that this resolver uses for determining type id from type. Mostly informational; not required to be called or used.