Top Description Inners Constructors Methods
tools.jackson.databind

public abstract Class JacksonModule

extends Object
implements Versioned
Class Inheritance
All Implemented Interfaces
tools.jackson.core.Versioned
Known Direct Subclasses
tools.jackson.databind.module.SimpleModule
Imports
java.util.Collection, .Collections, java.util.function.UnaryOperator, tools.jackson.core.*, tools.jackson.databind.cfg.*, tools.jackson.databind.deser.*, tools.jackson.databind.jsontype.NamedType, tools.jackson.databind.ser.Serializers, .ValueSerializerModifier, tools.jackson.databind.type.TypeFactory, .TypeModifier

Simple interface for extensions that can be registered with ObjectMapper to provide a well-defined set of extensions to default functionality; such as support for new data types.

Note

was named just Module in Jackson 2.x but renamed due to naming conflict with Java 9+ java.lang.Module

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static interface
JacksonModule.SetupContext

Interface Jackson exposes to modules for purpose of registering extended functionality.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public Iterable<? extends JacksonModule>
getDependencies()

Returns the list of dependent modules this module has, if any.

public abstract String
getModuleName()

Method that returns a display that can be used by Jackson for informational purposes, as well as in associating extensions with module that provides them.

public Object
getRegistrationId()

Method that returns an id that may be used to determine if two JacksonModule instances are considered to be of same type, for purpose of preventing multiple registrations of "same" module,

Default implementation returns value of class name (Class#getName).

public abstract void
setupModule(JacksonModule.SetupContext context)

Method called by ObjectMapper when module is registered.

public abstract Version
version()

Redeclares tools.jackson.core.Versioned.version.

Method that returns version of this module.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

JacksonModuleback to summary
public JacksonModule()

Method Detail

getDependenciesback to summary
public Iterable<? extends JacksonModule> getDependencies()

Returns the list of dependent modules this module has, if any. It is called to let modules register other modules as dependencies. Modules returned will be registered before this module is registered, in iteration order.

getModuleNameback to summary
public abstract String getModuleName()

Method that returns a display that can be used by Jackson for informational purposes, as well as in associating extensions with module that provides them.

getRegistrationIdback to summary
public Object getRegistrationId()

Method that returns an id that may be used to determine if two JacksonModule instances are considered to be of same type, for purpose of preventing multiple registrations of "same" module,

Default implementation returns value of class name (Class#getName).

Since
3.0
setupModuleback to summary
public abstract void setupModule(JacksonModule.SetupContext context)

Method called by ObjectMapper when module is registered. It is called to let module register functionality it provides, using callback methods passed-in context object exposes.

versionback to summary
public abstract Version version()

Redeclares tools.jackson.core.Versioned.version.

Method that returns version of this module. Can be used by Jackson for informational purposes.

Annotations
@Override
tools.jackson.databind back to summary

public Interface JacksonModule.SetupContext

Known Direct Implementers
tools.jackson.databind.cfg.ModuleContextBase

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 SetupContext#getOwner method.

Method Summary

Modifier and TypeMethod and Description
public JacksonModule.SetupContext
addAbstractTypeResolver(AbstractTypeResolver
Resolver to add.
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).

public JacksonModule.SetupContext
addDeserializerModifier(ValueDeserializerModifier
Modifier to register
mod
)

Method that module can use to register additional modifier objects to customize configuration and construction of bean deserializers.

public JacksonModule.SetupContext
addDeserializers(Deserializers
Object that can be called to find deserializer for types supported by module (null returned for non-supported types)
d
)

Method that module can use to register additional deserializers to use for handling types.

public JacksonModule.SetupContext
addHandler(DeserializationProblemHandler
The deserialization problem handler
handler
)

Add a deserialization problem handler

public JacksonModule.SetupContext
addKeyDeserializers(KeyDeserializers s)

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)

public JacksonModule.SetupContext
addKeySerializers(Serializers s)

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

public JacksonModule.SetupContext
addSerializerModifier(ValueSerializerModifier
Modifier to register
mod
)

Method that module can use to register additional modifier objects to customize configuration and construction of bean serializers.

public JacksonModule.SetupContext
addSerializers(Serializers
Object that can be called to find serializer for types supported by module (null returned for non-supported types)
s
)

Method that module can use to register additional serializers to use for handling types.

public JacksonModule.SetupContext
addTypeModifier(TypeModifier
to add
modifier
)

Method that module can use to register additional TypeModifier instance, which can augment tools.jackson.databind.JavaType instances constructed by tools.jackson.databind.type.TypeFactory.

public JacksonModule.SetupContext
addValueInstantiators(ValueInstantiators
Object that can provide tools.jackson.databind.deser.ValueInstantiators for constructing POJO values during deserialization
instantiators
)

Method that module can use to register additional tools.jackson.databind.deser.ValueInstantiators, by adding ValueInstantiators object that gets called when instantatiator is needed by a deserializer.

public JacksonModule.SetupContext
appendAnnotationIntrospector(AnnotationIntrospector
Annotation introspector to register.
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.

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

public DatatypeFeatures
public String
public Version
getMapperVersion()

Method that returns version information about ObjectMapper that implements this context.

public Object
getOwner()

Fallback access method that allows modules to refer to the MapperBuilder that provided this context.

public JacksonModule.SetupContext
insertAnnotationIntrospector(AnnotationIntrospector
Annotation introspector to register.
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)

public boolean
public boolean
public boolean
public boolean
public boolean
public boolean
public boolean
public JacksonModule.SetupContext
overrideDefaultNullKeySerializer(ValueSerializer<?>
Serializer called to write output for JSON Object key of which value on Java side is `null`
ser
)

Method that module can use to override handler called to write JSON Object key for java.util.Map values.

public JacksonModule.SetupContext
overrideDefaultNullValueSerializer(ValueSerializer<?>
Serializer called to write output for Java `null` as value (as distinct from key)
ser
)

Method that module can use to override handler called to write Java `null` as a value (Property or Map value, Collection/array element).

public JacksonModule.SetupContext
overrideInjectableValues(UnaryOperator<InjectableValues> v)

Replace default InjectableValues that have been configured to be used for mapper being built.

public JacksonModule.SetupContext
registerSubtypes(Class<?>... subtypes)

Method for registering specified classes as subtypes (of supertype(s) they have)

public JacksonModule.SetupContext
registerSubtypes(NamedType... subtypes)

Method for registering specified classes as subtypes (of supertype(s) they have), using specified type names.

public JacksonModule.SetupContext
registerSubtypes(Collection<Class<?>> subtypes)

Method for registering specified classes as subtypes (of supertype(s) they have)

public JacksonModule.SetupContext
setMixIn(Class<?>
Class (or interface) whose annotations to effectively override
target
,
Class<?>
Class (or interface) whose annotations are to be "added" to target's annotations, overriding as necessary
mixinSource
)

Method used for defining mix-in annotations to use for augmenting specified class or interface.

public TokenStreamFactory
public TypeFactory
typeFactory()

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

Method Detail

addAbstractTypeResolverback to summary
public 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:AbstractTypeResolver

Resolver to add.

addDeserializerModifierback to summary
public JacksonModule.SetupContext addDeserializerModifier(ValueDeserializerModifier mod)

Method that module can use to register additional modifier objects to customize configuration and construction of bean deserializers.

Parameters
mod:ValueDeserializerModifier

Modifier to register

addDeserializersback to summary
public JacksonModule.SetupContext addDeserializers(Deserializers d)

Method that module can use to register additional deserializers to use for handling types.

Parameters
d:Deserializers

Object that can be called to find deserializer for types supported by module (null returned for non-supported types)

See Also
is used to register key deserializers (for Map keys)
addHandlerback to summary
public JacksonModule.SetupContext addHandler(DeserializationProblemHandler handler)

Add a deserialization problem handler

Parameters
handler:DeserializationProblemHandler

The deserialization problem handler

addKeyDeserializersback to summary
public JacksonModule.SetupContext addKeyDeserializers(KeyDeserializers s)

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)

addKeySerializersback to summary
public JacksonModule.SetupContext addKeySerializers(Serializers s)

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

addSerializerModifierback to summary
public JacksonModule.SetupContext addSerializerModifier(ValueSerializerModifier mod)

Method that module can use to register additional modifier objects to customize configuration and construction of bean serializers.

Parameters
mod:ValueSerializerModifier

Modifier to register

addSerializersback to summary
public JacksonModule.SetupContext addSerializers(Serializers s)

Method that module can use to register additional serializers to use for handling types.

Parameters
s:Serializers

Object that can be called to find serializer for types supported by module (null returned for non-supported types)

See Also
is used to register key serializers (for Map keys)
addTypeModifierback to summary
public JacksonModule.SetupContext addTypeModifier(TypeModifier modifier)

Method that module can use to register additional TypeModifier instance, which can augment tools.jackson.databind.JavaType instances constructed by tools.jackson.databind.type.TypeFactory.

Parameters
modifier:TypeModifier

to add

addValueInstantiatorsback to summary
public JacksonModule.SetupContext addValueInstantiators(ValueInstantiators instantiators)

Method that module can use to register additional tools.jackson.databind.deser.ValueInstantiators, by adding ValueInstantiators object that gets called when instantatiator is needed by a deserializer.

Parameters
instantiators:ValueInstantiators

Object that can provide tools.jackson.databind.deser.ValueInstantiators for constructing POJO values during deserialization

appendAnnotationIntrospectorback to summary
public 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:AnnotationIntrospector

Annotation introspector to register.

configOverrideback to summary
public 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 java.util.Date (possibly further overridden by per-property annotations)
datatypeFeaturesback to summary
public DatatypeFeatures datatypeFeatures()
getFormatNameback to summary
public String getFormatName()
Since
3.0
getMapperVersionback to summary
public 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.

getOwnerback to summary
public 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).

insertAnnotationIntrospectorback to summary
public 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:AnnotationIntrospector

Annotation introspector to register.

isEnabledback to summary
public boolean isEnabled(MapperFeature f)
isEnabledback to summary
public boolean isEnabled(DeserializationFeature f)
isEnabledback to summary
public boolean isEnabled(SerializationFeature f)
isEnabledback to summary
public boolean isEnabled(TokenStreamFactory.Feature f)
isEnabledback to summary
public boolean isEnabled(StreamReadFeature f)
isEnabledback to summary
public boolean isEnabled(StreamWriteFeature f)
isEnabledback to summary
public boolean isEnabled(DatatypeFeature f)
overrideDefaultNullKeySerializerback to summary
public JacksonModule.SetupContext overrideDefaultNullKeySerializer(ValueSerializer<?> ser)

Method that module can use to override handler called to write JSON Object key for java.util.Map values.

Parameters
ser:ValueSerializer<?>

Serializer called to write output for JSON Object key of which value on Java side is `null`

overrideDefaultNullValueSerializerback to summary
public 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:ValueSerializer<?>

Serializer called to write output for Java `null` as value (as distinct from key)

overrideInjectableValuesback to summary
public JacksonModule.SetupContext overrideInjectableValues(UnaryOperator<InjectableValues> v)

Replace default InjectableValues that have been configured to be used for mapper being built.

Since
3.0
registerSubtypesback to summary
public JacksonModule.SetupContext registerSubtypes(Class<?>... subtypes)

Method for registering specified classes as subtypes (of supertype(s) they have)

registerSubtypesback to summary
public JacksonModule.SetupContext registerSubtypes(NamedType... subtypes)

Method for registering specified classes as subtypes (of supertype(s) they have), using specified type names.

registerSubtypesback to summary
public JacksonModule.SetupContext registerSubtypes(Collection<Class<?>> subtypes)

Method for registering specified classes as subtypes (of supertype(s) they have)

setMixInback to summary
public 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<?>

Class (or interface) whose annotations to effectively override

mixinSource:Class<?>

Class (or interface) whose annotations are to be "added" to target's annotations, overriding as necessary

tokenStreamFactoryback to summary
public TokenStreamFactory tokenStreamFactory()
typeFactoryback to summary
public 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.