Interface TypeResolverBuilder<T extends TypeResolverBuilder<T>>

All Known Implementing Classes:
DefaultTypeResolverBuilder, StdTypeResolverBuilder

public interface TypeResolverBuilder<T extends TypeResolverBuilder<T>>
Interface that defines builders that are configured based on annotations (like JsonTypeInfo or JAXB annotations), and produce type serializers and deserializers used for handling type information embedded in JSON to allow for safe polymorphic type handling.

Builder is first initialized by calling init(com.fasterxml.jackson.annotation.JsonTypeInfo.Value, tools.jackson.databind.jsontype.TypeIdResolver) method. Finally, after calling all configuration methods, buildTypeSerializer(tools.jackson.databind.SerializationContext, tools.jackson.databind.JavaType, java.util.Collection<tools.jackson.databind.jsontype.NamedType>) or buildTypeDeserializer(tools.jackson.databind.DeserializationContext, tools.jackson.databind.JavaType, java.util.Collection<tools.jackson.databind.jsontype.NamedType>) will be called to get actual type resolver constructed and used for resolving types for configured base type and its subtypes.

Note that instances are used for two related but distinct use cases:

  • To create builders to use with explicit type information inclusion (usually via @JsonTypeInfo annotation)
  • To create builders when "default typing" is used; if so, type information is automatically included for certain kind of types, regardless of annotations
Important distinction between the cases is that in first case, calls to create builders are only made when builders are certainly needed; whereas in second case builder has to first verify whether type information is applicable for given type, and if not, just return null to indicate this.
  • Method Details

    • getDefaultImpl

      Class<?> getDefaultImpl()
      Accessor for currently configured default type; implementation class that may be used in case no valid type information is available during type resolution
    • buildTypeSerializer

      TypeSerializer buildTypeSerializer(SerializationContext ctxt, JavaType baseType, Collection<NamedType> subtypes)
      Method for building type serializer based on current configuration of this builder.
      Parameters:
      baseType - Base type that constructed resolver will handle; super type of all types it will be used for.
    • buildTypeDeserializer

      TypeDeserializer buildTypeDeserializer(DeserializationContext ctxt, JavaType baseType, Collection<NamedType> subtypes)
      Method for building type deserializer based on current configuration of this builder.
      Parameters:
      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.
    • init

      T init(JsonTypeInfo.Value settings, TypeIdResolver res)
      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)
      Parameters:
      settings - Configuration settings to apply.
      Returns:
      Resulting builder instance (usually this builder, but not necessarily)
    • withDefaultImpl

      T 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.

      In Jackson 2.x there was instead method defaultImpl() which was a mutator: this method MUST NOT change the underlying state.

      Returns:
      Either this instance (if nothing changed) or a new instance with different default implementation
    • withSettings

      T withSettings(JsonTypeInfo.Value typeInfo)
      Method for overriding type information.