Interface JacksonModule.SetupContext

All Known Implementing Classes:
ModuleContextBase
Enclosing class:
JacksonModule

public static interface JacksonModule.SetupContext
Interface Jackson exposes to modules for purpose of registering extended functionality. Usually implemented by ObjectMapper, but modules should NOT rely on this -- if they do require access to mapper instance, they need to call getOwner() method.
  • Method Details

    • getMapperVersion

      Version getMapperVersion()
      Method that returns version information about ObjectMapper that implements this context. Modules can use this to choose different settings or initialization order; or even decide to fail set up completely if version is compatible with module.
    • getFormatName

      String getFormatName()
      Since:
      3.0
    • getOwner

      Object getOwner()
      Fallback access method that allows modules to refer to the MapperBuilder that provided this context. It should NOT be needed by most modules; and ideally should not be used -- however, there may be cases where this may be necessary due to various design constraints.

      NOTE: use of this method is discouraged, as it allows access to things Modules typically should not modify. It is included, however, to allow access to new features in cases where Module API has not yet been extended, or there are oversights.

      Return value is chosen to force casting, to make caller aware that this is a fallback accessor, used only when everything else fails: type is, however, guaranteed to be MapperBuilder (and more specifically format-specific subtype that mapper constructed, in case format-specific access is needed).

    • typeFactory

      TypeFactory typeFactory()
      Accessor for finding TypeFactory that is currently configured by the context.

      NOTE: since it is possible that other modules might change or replace TypeFactory, use of this method adds order-dependency for registrations.

    • tokenStreamFactory

      TokenStreamFactory tokenStreamFactory()
    • isEnabled

      boolean isEnabled(MapperFeature f)
    • isEnabled

      boolean isEnabled(DeserializationFeature f)
    • isEnabled

      boolean isEnabled(SerializationFeature f)
    • isEnabled

      boolean isEnabled(TokenStreamFactory.Feature f)
    • isEnabled

      boolean isEnabled(StreamReadFeature f)
    • isEnabled

      boolean isEnabled(StreamWriteFeature f)
    • configOverride

      MutableConfigOverride configOverride(Class<?> type)
      "Mutant accessor" for getting a mutable configuration override object for given type, needed to add or change per-type overrides applied to properties of given type. Usage is through returned object by colling "setter" methods, which directly modify override object and take effect directly. For example you can do
         mapper.configOverride(java.util.Date.class)
             .setFormat(JsonFormat.Value.forPattern("yyyy-MM-dd"));
      
      to change the default format to use for properties of type Date (possibly further overridden by per-property annotations)
    • addDeserializers

      Method that module can use to register additional deserializers to use for handling types.
      Parameters:
      d - Object that can be called to find deserializer for types supported by module (null returned for non-supported types)
      See Also:
    • addKeyDeserializers

      Method that module can use to register additional deserializers to use for handling Map key values (which are separate from value deserializers because they are always serialized from String values)
    • addDeserializerModifier

      Method that module can use to register additional modifier objects to customize configuration and construction of bean deserializers.
      Parameters:
      mod - Modifier to register
    • addValueInstantiators

      JacksonModule.SetupContext addValueInstantiators(ValueInstantiators instantiators)
      Method that module can use to register additional ValueInstantiators, by adding ValueInstantiators object that gets called when instantatiator is needed by a deserializer.
      Parameters:
      instantiators - Object that can provide ValueInstantiators for constructing POJO values during deserialization
    • addSerializers

      Method that module can use to register additional serializers to use for handling types.
      Parameters:
      s - Object that can be called to find serializer for types supported by module (null returned for non-supported types)
      See Also:
    • addKeySerializers

      Method that module can use to register additional serializers to use for handling Map key values (which are separate from value serializers because they must write JsonToken.FIELD_NAME instead of String value).
    • addSerializerModifier

      Method that module can use to register additional modifier objects to customize configuration and construction of bean serializers.
      Parameters:
      mod - Modifier to register
    • overrideDefaultNullKeySerializer

      JacksonModule.SetupContext overrideDefaultNullKeySerializer(ValueSerializer<?> ser)
      Method that module can use to override handler called to write JSON Object key for Map values.
      Parameters:
      ser - Serializer called to write output for JSON Object key of which value on Java side is `null`
    • overrideDefaultNullValueSerializer

      JacksonModule.SetupContext overrideDefaultNullValueSerializer(ValueSerializer<?> ser)
      Method that module can use to override handler called to write Java `null` as a value (Property or Map value, Collection/array element).
      Parameters:
      ser - Serializer called to write output for Java `null` as value (as distinct from key)
    • insertAnnotationIntrospector

      JacksonModule.SetupContext insertAnnotationIntrospector(AnnotationIntrospector ai)
      Method for registering specified AnnotationIntrospector as the highest priority introspector (will be chained with existing introspector(s) which will be used as fallbacks for cases this introspector does not handle)
      Parameters:
      ai - Annotation introspector to register.
    • appendAnnotationIntrospector

      JacksonModule.SetupContext appendAnnotationIntrospector(AnnotationIntrospector ai)
      Method for registering specified AnnotationIntrospector as the lowest priority introspector, chained with existing introspector(s) and called as fallback for cases not otherwise handled.
      Parameters:
      ai - Annotation introspector to register.
    • addAbstractTypeResolver

      JacksonModule.SetupContext addAbstractTypeResolver(AbstractTypeResolver resolver)
      Method that module can use to register additional AbstractTypeResolver instance, to handle resolution of abstract to concrete types (either by defaulting, or by materializing).
      Parameters:
      resolver - Resolver to add.
    • addTypeModifier

      JacksonModule.SetupContext addTypeModifier(TypeModifier modifier)
      Method that module can use to register additional TypeModifier instance, which can augment JavaType instances constructed by TypeFactory.
      Parameters:
      modifier - to add
    • registerSubtypes

      JacksonModule.SetupContext registerSubtypes(Class<?>... subtypes)
      Method for registering specified classes as subtypes (of supertype(s) they have)
    • registerSubtypes

      JacksonModule.SetupContext registerSubtypes(NamedType... subtypes)
      Method for registering specified classes as subtypes (of supertype(s) they have), using specified type names.
    • registerSubtypes

      JacksonModule.SetupContext registerSubtypes(Collection<Class<?>> subtypes)
      Method for registering specified classes as subtypes (of supertype(s) they have)
    • addHandler

      Add a deserialization problem handler
      Parameters:
      handler - The deserialization problem handler
    • overrideInjectableValues

      Replace default InjectableValues that have been configured to be used for mapper being built.
      Since:
      3.0
    • setMixIn

      JacksonModule.SetupContext setMixIn(Class<?> target, Class<?> mixinSource)
      Method used for defining mix-in annotations to use for augmenting specified class or interface. All annotations from mixinSource are taken to override annotations that target (or its supertypes) has.

      Note: mix-ins are registered both for serialization and deserialization (which can be different internally).

      Note: currently only one set of mix-in annotations can be defined for a single class; so if multiple modules register mix-ins, highest priority one (last one registered) will have priority over other modules.

      Parameters:
      target - Class (or interface) whose annotations to effectively override
      mixinSource - Class (or interface) whose annotations are to be "added" to target's annotations, overriding as necessary