Top Description Fields Constructors Methods
com.fasterxml.jackson.databind.module

public Class SimpleModule

extends Module
implements Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable
Imports
java.util.Collection, .HashMap, .LinkedHashSet, .List, .Map, java.util.concurrent.atomic.AtomicInteger, com.fasterxml.jackson.core.Version, com.fasterxml.jackson.databind.*, com.fasterxml.jackson.databind.deser.BeanDeserializerModifier, .ValueInstantiator, com.fasterxml.jackson.databind.jsontype.NamedType, com.fasterxml.jackson.databind.ser.BeanSerializerModifier

Vanilla com.fasterxml.jackson.databind.Module implementation that allows registration of serializers and deserializers, bean serializer and deserializer modifiers, registration of subtypes and mix-ins as well as some other commonly needed aspects (addition of custom AbstractTypeResolvers, com.fasterxml.jackson.databind.deser.ValueInstantiators).

Note

that [de]serializers are registered as "default" [de]serializers. As a result, they will have lower priority than the ones indicated through annotations on both Class and property-associated annotations -- for example, com.fasterxml.jackson.databind.annotation.JsonDeserialize.
In cases where both module-based [de]serializers and annotation-based [de]serializers are registered, the [de]serializer specified by the annotation will take precedence.

Note

although it is not expected that sub-types should need to override setupModule(SetupContext) method, if they choose to do so they MUST call super.setupModule(context); to ensure that registration works as expected.

Warning

when registering JsonSerializers and JsonDeserializers, only type erased Class is compared: this means that usually you should NOT use this implementation for registering structured types such as java.util.Collections or java.util.Maps: this because parametric type information will not be considered and you may end up having "wrong" handler for your type. What you need to do, instead, is to implement com.fasterxml.jackson.databind.deser.Deserializers and/or com.fasterxml.jackson.databind.ser.Serializers callbacks to match full type signatures (with JavaType).

Field Summary

Modifier and TypeField and Description
protected SimpleAbstractTypeResolver
_abstractTypes

Lazily-constructed resolver used for storing mappings from abstract classes to more specific implementing classes (which may be abstract or concrete)

protected BeanDeserializerModifier
protected SimpleDeserializers
protected final boolean
_hasExplicitName

Flag that indicates whether module was given an explicit name or not.

protected SimpleKeyDeserializers
protected SimpleSerializers
protected HashMap<Class<?>, Class<?>>
_mixins

Lazily-constructed map that contains mix-in definitions, indexed by target class, value being mix-in to apply.

protected final String
protected PropertyNamingStrategy
protected BeanSerializerModifier
protected SimpleSerializers
protected LinkedHashSet<NamedType>
_subtypes

Set of subtypes to register, if any.

protected SimpleValueInstantiators
_valueInstantiators

Lazily-constructed resolver used for storing mappings from abstract classes to more specific implementing classes (which may be abstract or concrete)

protected final Version
private static final AtomicInteger
private static final long

Constructor Summary

AccessConstructor and Description
public
SimpleModule()

Constructors that should only be used for non-reusable convenience modules used by app code: "real" modules should use actual name and version number information.

public
SimpleModule(String name)

Convenience constructor that will default version to Version#unknownVersion().

public
SimpleModule(Version version)

Convenience constructor that will use specified Version, including name from Version#getArtifactId().

public
SimpleModule(String
Unique name of the module
name
,
Version
Version of the module
version
)

Constructor to use for actual reusable modules.

public
SimpleModule(String name, Version version, Map<Class<?>, JsonDeserializer<?>> deserializers)

public
SimpleModule(String name, Version version, List<JsonSerializer<?>> serializers)

public
SimpleModule(String name, Version version, Map<Class<?>, JsonDeserializer<?>> deserializers, List<JsonSerializer<?>> serializers)

Method Summary

Modifier and TypeMethod and Description
protected void
_checkNotNull(Object thingy, String type)

public <T> SimpleModule
addAbstractTypeMapping(Class<T> superType, Class<? extends T> subType)

Lazily-constructed resolver used for storing mappings from abstract classes to more specific implementing classes (which may be abstract or concrete)

public <T> SimpleModule
addDeserializer(Class<T> type, JsonDeserializer<? extends T> deser)

Method for adding deserializer to handle specified type.

public SimpleModule
addKeyDeserializer(Class<?> type, KeyDeserializer deser)

Note

This method registers "default" (de)serializers only.

public <T> SimpleModule
addKeySerializer(Class<? extends T> type, JsonSerializer<T> ser)

Note

This method registers "default" (de)serializers only.

public SimpleModule
addSerializer(JsonSerializer<?> ser)

Method for adding serializer to handle type that the serializer claims to handle (see JsonSerializer#handledType()).

public <T> SimpleModule
addSerializer(Class<? extends T> type, JsonSerializer<T> ser)

Method for adding serializer to handle values of specific type.

public SimpleModule
addValueInstantiator(Class<?> beanType, ValueInstantiator inst)

Method for registering ValueInstantiator to use when deserializing instances of type beanType.

public String
getModuleName()

Implements abstract com.fasterxml.jackson.databind.Module.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
getTypeId()

Overrides com.fasterxml.jackson.databind.Module.getTypeId.

Since instances are likely to be custom, implementation returns null if (but only if!) this class is directly instantiated; but class name (default impl) for sub-classes.

public SimpleModule
registerSubtypes(Class<?>... subtypes)

Method for adding set of subtypes to be registered with ObjectMapper this is an alternative to using annotations in super type to indicate subtypes.

public SimpleModule
registerSubtypes(NamedType... subtypes)

Method for adding set of subtypes (along with type name to use) to be registered with ObjectMapper this is an alternative to using annotations in super type to indicate subtypes.

public SimpleModule
registerSubtypes(Collection<Class<?>> subtypes)

Method for adding set of subtypes (along with type name to use) to be registered with ObjectMapper this is an alternative to using annotations in super type to indicate subtypes.

public void
setAbstractTypes(SimpleAbstractTypeResolver atr)

Resets currently configured abstract type mappings

public SimpleModule
public void
setDeserializers(SimpleDeserializers d)

Resets all currently configured deserializers.

public void
setKeyDeserializers(SimpleKeyDeserializers kd)

Resets all currently configured key deserializers.

public void
setKeySerializers(SimpleSerializers ks)

Resets all currently configured key serializers.

public SimpleModule
setMixInAnnotation(Class<?> targetType, Class<?> mixinClass)

Method for specifying that annotations define by mixinClass should be "mixed in" with annotations that targetType has (as if they were directly included on it!).

protected SimpleModule
public SimpleModule
public void
setSerializers(SimpleSerializers s)

Resets all currently configured serializers.

public void
setupModule(Module.SetupContext context)

Implements abstract com.fasterxml.jackson.databind.Module.setupModule.

Standard implementation handles registration of all configured customizations: it is important that sub-classes call this implementation (usually before additional custom logic) if they choose to override it; otherwise customizations will not be registered.

public void
setValueInstantiators(SimpleValueInstantiators svi)

Resets all currently configured value instantiators

public Version
version()

Implements abstract com.fasterxml.jackson.databind.Module.version.

Implements com.fasterxml.jackson.core.Versioned.version.

Method that returns version of this module.

Inherited from com.fasterxml.jackson.databind.Module:
getDependencies

Field Detail

_abstractTypesback to summary
protected SimpleAbstractTypeResolver _abstractTypes

Lazily-constructed resolver used for storing mappings from abstract classes to more specific implementing classes (which may be abstract or concrete)

_deserializerModifierback to summary
protected BeanDeserializerModifier _deserializerModifier
Since
2.2
_deserializersback to summary
protected SimpleDeserializers _deserializers
_hasExplicitNameback to summary
protected final boolean _hasExplicitName

Flag that indicates whether module was given an explicit name or not. Distinction is used to determine whether method getTypeId() should return name (yes, if explicit) or null (if no explicit name was passed).

Since
2.13
_keyDeserializersback to summary
protected SimpleKeyDeserializers _keyDeserializers
_keySerializersback to summary
protected SimpleSerializers _keySerializers
_mixinsback to summary
protected HashMap<Class<?>, Class<?>> _mixins

Lazily-constructed map that contains mix-in definitions, indexed by target class, value being mix-in to apply.

_nameback to summary
protected final String _name
_namingStrategyback to summary
protected PropertyNamingStrategy _namingStrategy
Since
2.3
_serializerModifierback to summary
protected BeanSerializerModifier _serializerModifier
Since
2.2
_serializersback to summary
protected SimpleSerializers _serializers
_subtypesback to summary
protected LinkedHashSet<NamedType> _subtypes

Set of subtypes to register, if any.

_valueInstantiatorsback to summary
protected SimpleValueInstantiators _valueInstantiators

Lazily-constructed resolver used for storing mappings from abstract classes to more specific implementing classes (which may be abstract or concrete)

_versionback to summary
protected final Version _version
MODULE_ID_SEQback to summary
private static final AtomicInteger MODULE_ID_SEQ
serialVersionUIDback to summary
private static final long serialVersionUID

Constructor Detail

SimpleModuleback to summary
public SimpleModule()

Constructors that should only be used for non-reusable convenience modules used by app code: "real" modules should use actual name and version number information.

SimpleModuleback to summary
public SimpleModule(String name)

Convenience constructor that will default version to Version#unknownVersion().

SimpleModuleback to summary
public SimpleModule(Version version)

Convenience constructor that will use specified Version, including name from Version#getArtifactId().

SimpleModuleback to summary
public SimpleModule(String name, Version version)

Constructor to use for actual reusable modules. ObjectMapper may use name as identifier to notice attempts for multiple registrations of the same module (although it does not have to).

Parameters
name:String

Unique name of the module

version:Version

Version of the module

SimpleModuleback to summary
public SimpleModule(String name, Version version, Map<Class<?>, JsonDeserializer<?>> deserializers)
Since
2.1
SimpleModuleback to summary
public SimpleModule(String name, Version version, List<JsonSerializer<?>> serializers)
Since
2.1
SimpleModuleback to summary
public SimpleModule(String name, Version version, Map<Class<?>, JsonDeserializer<?>> deserializers, List<JsonSerializer<?>> serializers)
Since
2.1

Method Detail

_checkNotNullback to summary
protected void _checkNotNull(Object thingy, String type)
Since
2.9
addAbstractTypeMappingback to summary
public <T> SimpleModule addAbstractTypeMapping(Class<T> superType, Class<? extends T> subType)

Lazily-constructed resolver used for storing mappings from abstract classes to more specific implementing classes (which may be abstract or concrete)

addDeserializerback to summary
public <T> SimpleModule addDeserializer(Class<T> type, JsonDeserializer<? extends T> deser)

Method for adding deserializer to handle specified type.

Warning

Type matching only uses type-erased Class and should NOT be used when registering serializers for generic types like java.util.Collection and java.util.Map.

Warning

"Last one wins" rule is applied. Possible earlier addition of a serializer for a given Class will be replaced.

Note

This method registers "default" (de)serializers only. See a note on precedence in class JavaDoc.

See Also
is used to register key deserializers (for Map keys)
addKeyDeserializerback to summary
public SimpleModule addKeyDeserializer(Class<?> type, KeyDeserializer deser)

Note

This method registers "default" (de)serializers only. See a note on precedence in class JavaDoc.

addKeySerializerback to summary
public <T> SimpleModule addKeySerializer(Class<? extends T> type, JsonSerializer<T> ser)

Note

This method registers "default" (de)serializers only. See a note on precedence in class JavaDoc.

addSerializerback to summary
public SimpleModule addSerializer(JsonSerializer<?> ser)

Method for adding serializer to handle type that the serializer claims to handle (see JsonSerializer#handledType()).

Warning

Type matching only uses type-erased Class and should NOT be used when registering serializers for generic types like java.util.Collection and java.util.Map.

Warning

"Last one wins" rule is applied. Possible earlier addition of a serializer for a given Class will be replaced.

Note

This method registers "default" (de)serializers only. See a note on precedence in class JavaDoc.

See Also
is used to register key serializers (for Map keys)
addSerializerback to summary
public <T> SimpleModule addSerializer(Class<? extends T> type, JsonSerializer<T> ser)

Method for adding serializer to handle values of specific type.

Note

This method registers "default" (de)serializers only. See a note on precedence in class JavaDoc.

Warning

Type matching only uses type-erased Class and should NOT be used when registering serializers for generic types like java.util.Collection and java.util.Map.

Warning

"Last one wins" rule is applied. Possible earlier addition of a serializer for a given Class will be replaced.

Note

This method registers "default" (de)serializers only. See a note on precedence in class JavaDoc.

See Also
is used to register key serializers (for Map keys)
addValueInstantiatorback to summary
public SimpleModule addValueInstantiator(Class<?> beanType, ValueInstantiator inst)

Method for registering ValueInstantiator to use when deserializing instances of type beanType.

Instantiator is registered when module is registered for ObjectMapper.

getModuleNameback to summary
public String getModuleName()

Implements abstract com.fasterxml.jackson.databind.Module.getModuleName.

Doc from com.fasterxml.jackson.databind.Module.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.

Annotations
@Override
getTypeIdback to summary
public Object getTypeId()

Overrides com.fasterxml.jackson.databind.Module.getTypeId.

Since instances are likely to be custom, implementation returns null if (but only if!) this class is directly instantiated; but class name (default impl) for sub-classes.

Annotations
@Override
registerSubtypesback to summary
public SimpleModule registerSubtypes(Class<?>... subtypes)

Method for adding set of subtypes to be registered with ObjectMapper this is an alternative to using annotations in super type to indicate subtypes.

registerSubtypesback to summary
public SimpleModule registerSubtypes(NamedType... subtypes)

Method for adding set of subtypes (along with type name to use) to be registered with ObjectMapper this is an alternative to using annotations in super type to indicate subtypes.

registerSubtypesback to summary
public SimpleModule registerSubtypes(Collection<Class<?>> subtypes)

Method for adding set of subtypes (along with type name to use) to be registered with ObjectMapper this is an alternative to using annotations in super type to indicate subtypes.

Since
2.9
setAbstractTypesback to summary
public void setAbstractTypes(SimpleAbstractTypeResolver atr)

Resets currently configured abstract type mappings

setDeserializerModifierback to summary
public SimpleModule setDeserializerModifier(BeanDeserializerModifier mod)
Since
2.2
setDeserializersback to summary
public void setDeserializers(SimpleDeserializers d)

Resets all currently configured deserializers.

setKeyDeserializersback to summary
public void setKeyDeserializers(SimpleKeyDeserializers kd)

Resets all currently configured key deserializers.

setKeySerializersback to summary
public void setKeySerializers(SimpleSerializers ks)

Resets all currently configured key serializers.

setMixInAnnotationback to summary
public SimpleModule setMixInAnnotation(Class<?> targetType, Class<?> mixinClass)

Method for specifying that annotations define by mixinClass should be "mixed in" with annotations that targetType has (as if they were directly included on it!).

Mix-in annotations are registered when module is registered for ObjectMapper.

setNamingStrategyback to summary
protected SimpleModule setNamingStrategy(PropertyNamingStrategy naming)
Since
2.3
setSerializerModifierback to summary
public SimpleModule setSerializerModifier(BeanSerializerModifier mod)
Since
2.2
setSerializersback to summary
public void setSerializers(SimpleSerializers s)

Resets all currently configured serializers.

setupModuleback to summary
public void setupModule(Module.SetupContext context)

Implements abstract com.fasterxml.jackson.databind.Module.setupModule.

Standard implementation handles registration of all configured customizations: it is important that sub-classes call this implementation (usually before additional custom logic) if they choose to override it; otherwise customizations will not be registered.

Annotations
@Override
setValueInstantiatorsback to summary
public void setValueInstantiators(SimpleValueInstantiators svi)

Resets all currently configured value instantiators

versionback to summary
public Version version()

Implements abstract com.fasterxml.jackson.databind.Module.version.

Implements com.fasterxml.jackson.core.Versioned.version.

Doc from com.fasterxml.jackson.databind.Module.version.

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

Returns:Version

Doc from com.fasterxml.jackson.core.Versioned.version.

Version of the component

Annotations
@Override