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

public Class ObjectMapper

extends ObjectCodec
implements Versioned, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, com.fasterxml.jackson.core.Versioned
Known Direct Subclasses
com.fasterxml.jackson.databind.json.JsonMapper
Imports
java.io.*, java.lang.reflect.Type, java.net.URL, java.security.AccessController, .PrivilegedAction, java.text.DateFormat, java.util.*, java.util.concurrent.ConcurrentHashMap, java.util.concurrent.atomic.AtomicReference, java.util.function.Consumer, com.fasterxml.jackson.annotation.*, com.fasterxml.jackson.core.*, com.fasterxml.jackson.core.exc.StreamReadException, .StreamWriteException, com.fasterxml.jackson.core.io.CharacterEscapes, .SegmentedStringWriter, com.fasterxml.jackson.core.type.ResolvedType, .TypeReference, com.fasterxml.jackson.core.util.*, com.fasterxml.jackson.databind.cfg.*, com.fasterxml.jackson.databind.deser.*, com.fasterxml.jackson.databind.exc.MismatchedInputException, com.fasterxml.jackson.databind.introspect.*, com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitorWrapper, com.fasterxml.jackson.databind.jsontype.*, com.fasterxml.jackson.databind.jsontype.impl.LaissezFaireSubTypeValidator, .StdSubtypeResolver, .StdTypeResolverBuilder, com.fasterxml.jackson.databind.node.*, com.fasterxml.jackson.databind.ser.*, com.fasterxml.jackson.databind.type.*, com.fasterxml.jackson.databind.util.ClassUtil, .RootNameLookup, .StdDateFormat, .TokenBuffer

ObjectMapper provides functionality for reading and writing JSON, either to and from basic POJOs (Plain Old Java Objects), or to and from a general-purpose JSON Tree Model (JsonNode), as well as related functionality for performing conversions. It is also highly customizable to work both with different styles of JSON content, and to support more advanced Object concepts such as polymorphism and Object identity. ObjectMapper also acts as a factory for more advanced ObjectReader and ObjectWriter classes. Mapper (and ObjectReaders, ObjectWriters it constructs) will use instances of JsonParser and JsonGenerator for implementing actual reading/writing of JSON. Note that although most read and write methods are exposed through this class, some of the functionality is only exposed via ObjectReader and ObjectWriter: specifically, reading/writing of longer sequences of values is only available through ObjectReader#readValues(InputStream) and ObjectWriter#writeValues(OutputStream).

Simplest usage is of form:

  final ObjectMapper mapper = new ObjectMapper(); // can use static singleton, inject: just make sure to reuse!
  MyValue value = new MyValue();
  // ... and configure
  File newState = new File("my-stuff.json");
  mapper.writeValue(newState, value); // writes JSON serialization of MyValue instance
  // or, read
  MyValue older = mapper.readValue(new File("my-older-stuff.json"), MyValue.class);

  // Or if you prefer JSON Tree representation:
  JsonNode root = mapper.readTree(newState);
  // and find values by, for example, using a com.fasterxml.jackson.core.JsonPointer expression:
  int age = root.at("/personal/age").getValueAsInt();

The main conversion API is defined in ObjectCodec, so that implementation details of this class need not be exposed to streaming parser and generator classes. Usage via ObjectCodec is, however, usually only for cases where dependency to ObjectMapper is either not possible (from Streaming API), or undesireable (when only relying on Streaming API).

Mapper instances are fully thread-safe provided that ALL configuration of the instance occurs before ANY read or write calls. If configuration of a mapper instance is modified after first usage, changes may or may not take effect, and configuration calls themselves may fail. If you need to use different configuration, you have two main possibilities:

Note on caching: root-level deserializers are always cached, and accessed using full (generics-aware) type information. This is different from caching of referenced types, which is more limited and is done only for a subset of all deserializer types. The main reason for difference is that at root-level there is no incoming reference (and hence no referencing property, no referral information or annotations to produce differing deserializers), and that the performance impact greatest at root level (since it'll essentially cache the full graph of deserializers involved).

Notes

on security: use of "default typing" feature (see enableDefaultTyping()) is a potential security risk, if used with untrusted content (content generated by untrusted external parties). If so, you may want to construct a custom TypeResolverBuilder implementation to limit possible types to instantiate, (using setDefaultTyping).

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
ObjectMapper.DefaultTypeResolverBuilder

Customized TypeResolverBuilder that provides type resolver builders used with so-called "default typing" (see ObjectMapper#activateDefaultTyping(PolymorphicTypeValidator) for details).

public static enum
ObjectMapper.DefaultTyping

Enumeration used with ObjectMapper#activateDefaultTyping(PolymorphicTypeValidator) to specify what kind of types (classes) default typing should be used for.

Field Summary

Modifier and TypeField and Description
protected final CoercionConfigs
_coercionConfigs

Current set of coercion configuration definitions that define allowed (and not allowed) coercions from secondary shapes.

protected final ConfigOverrides
_configOverrides

Currently active per-type configuration overrides, accessed by declared type of property.

protected DeserializationConfig
_deserializationConfig

Configuration object that defines basic global settings for the serialization process

protected DefaultDeserializationContext
_deserializationContext

Blueprint context object; stored here to allow custom sub-classes.

protected InjectableValues
_injectableValues

Provider for values to inject in deserialized POJOs.

protected final JsonFactory
_jsonFactory

Factory used to create JsonParser and JsonGenerator instances as necessary.

protected SimpleMixInResolver
_mixIns

Mapping that defines how to apply mix-in annotations: key is the type to received additional annotations, and value is the type that has annotations to "mix in".

protected Set<Object>
_registeredModuleTypes

Set of module types (as per Module#getTypeId() that have been registered; kept track of iff MapperFeature#IGNORE_DUPLICATE_MODULE_REGISTRATIONS is enabled, so that duplicate registration calls can be ignored (to avoid adding same handlers multiple times, mostly).

protected final ConcurrentHashMap<JavaType, JsonDeserializer<Object>>
_rootDeserializers

We will use a separate main-level Map for keeping track of root-level deserializers.

protected SerializationConfig
_serializationConfig

Configuration object that defines basic global settings for the serialization process

protected SerializerFactory
_serializerFactory

Serializer factory used for constructing serializers.

protected DefaultSerializerProvider
_serializerProvider

Object that manages access to serializers used for serialization, including caching.

protected SubtypeResolver
_subtypeResolver

Thing used for registering sub-types, resolving them to super/sub-types as needed.

protected TypeFactory
_typeFactory

Specific factory used for creating JavaType instances; needed to allow modules to add more custom type handling (mostly to support types of non-Java JVM languages)

protected static final AnnotationIntrospector
protected static final BaseSettings
DEFAULT_BASE

Base settings contain defaults used for all ObjectMapper instances.

private static final long

Constructor Summary

AccessConstructor and Description
public
ObjectMapper()

Default constructor, which will construct the default JsonFactory as necessary, use SerializerProvider as its SerializerProvider, and BeanSerializerFactory as its SerializerFactory.

public
ObjectMapper(JsonFactory jf)

Constructs instance that uses specified JsonFactory for constructing necessary JsonParsers and/or JsonGenerators.

protected
ObjectMapper(ObjectMapper src)

Copy-constructor, mostly used to support copy.

protected
ObjectMapper(ObjectMapper src, JsonFactory factory)

Copy-constructor, mostly used to support copyWith(JsonFactory).

public
ObjectMapper(JsonFactory
JsonFactory to use: if null, a new MappingJsonFactory will be constructed
jf
,
DefaultSerializerProvider
SerializerProvider to use: if null, a SerializerProvider will be constructed
sp
,
DefaultDeserializationContext
Blueprint deserialization context instance to use for creating actual context objects; if null, will construct standard DeserializationContext
dc
)

Constructs instance that uses specified JsonFactory for constructing necessary JsonParsers and/or JsonGenerators, and uses given providers for accessing serializers and deserializers.

Method Summary

Modifier and TypeMethod and Description
protected final void
_assertNotNull(String paramName, Object src)

protected void
protected final void
_configAndWriteValue(JsonGenerator g, Object value)
Deprecated Since 2.11.2 Use _writeValueAndClose instead

protected TypeResolverBuilder<?>
_constructDefaultTypeResolverBuilder(ObjectMapper.DefaultTyping applicability, PolymorphicTypeValidator ptv)

Overridable factory method, separate to allow format-specific mappers (and specifically XML-backed one, currently) to offer custom TypeResolverBuilder subtypes.

protected Object
_convert(Object fromValue, JavaType toValueType)

Actual conversion implementation: instead of using existing read and write methods, much of code is inlined.

protected JsonDeserializer<Object>
_findRootDeserializer(DeserializationContext ctxt, JavaType valueType)

Method called to locate deserializer for the passed root-level value.

protected JsonToken

Returns:

First token to be used for data binding after this call: can never be null as exception will be thrown if parser cannot provide more tokens.
_initForReading
(JsonParser p, JavaType targetType)

Method called to ensure that given parser is ready for reading content for data binding.

protected ObjectReader
_newReader(DeserializationConfig config)

Factory method sub-classes must override, to produce ObjectReader instances of proper sub-type

protected ObjectReader
_newReader(DeserializationConfig config, JavaType valueType, Object valueToUpdate, FormatSchema schema, InjectableValues injectableValues)

Factory method sub-classes must override, to produce ObjectReader instances of proper sub-type

protected ObjectWriter
_newWriter(SerializationConfig config)

Factory method sub-classes must override, to produce ObjectWriter instances of proper sub-type

protected ObjectWriter
_newWriter(SerializationConfig config, FormatSchema schema)

Factory method sub-classes must override, to produce ObjectWriter instances of proper sub-type

protected ObjectWriter
_newWriter(SerializationConfig config, JavaType rootType, PrettyPrinter pp)

Factory method sub-classes must override, to produce ObjectWriter instances of proper sub-type

protected Object
protected JsonNode
_readTreeAndClose(JsonParser p0)

Similar to _readMapAndClose but specialized for JsonNode reading.

protected Object
_readValue(DeserializationConfig cfg, JsonParser p, JavaType valueType)

Actual implementation of value reading+binding operation.

protected DefaultSerializerProvider
_serializerProvider(SerializationConfig config)

Overridable helper method used for constructing SerializerProvider to use for serialization.

protected final void
protected void
private final void
_writeCloseable(JsonGenerator g, Object value, SerializationConfig cfg)

Helper method used when value to serialize is Closeable and its close() method is to be called right after serialization has been called

private final void
_writeCloseableValue(JsonGenerator g, Object value, SerializationConfig cfg)

Helper method used when value to serialize is Closeable and its close() method is to be called right after serialization has been called

protected final void
_writeValueAndClose(JsonGenerator g, Object value)

Method called to configure the generator as necessary and then call write functionality

public void
acceptJsonFormatVisitor(Class<?>
Type to generate schema for (possibly with generic signature)
type
,
JsonFormatVisitorWrapper visitor)

Method for visiting type hierarchy for given type, using specified visitor.

public void
acceptJsonFormatVisitor(JavaType
Type to generate schema for (possibly with generic signature)
type
,
JsonFormatVisitorWrapper visitor)

Method for visiting type hierarchy for given type, using specified visitor.

public ObjectMapper
activateDefaultTyping(PolymorphicTypeValidator
Validator used to verify that actual subtypes to deserialize are valid against whatever criteria validator uses: important in case where untrusted content is deserialized.
ptv
)

Convenience method that is equivalent to calling

  activateDefaultTyping(ptv, DefaultTyping.OBJECT_AND_NON_CONCRETE);
public ObjectMapper
activateDefaultTyping(PolymorphicTypeValidator
Validator used to verify that actual subtypes to deserialize are valid against whatever criteria validator uses: important in case where untrusted content is deserialized.
ptv
,
ObjectMapper.DefaultTyping
Defines kinds of types for which additional type information is added; see DefaultTyping for more information.
applicability
)

Convenience method that is equivalent to calling

  activateDefaultTyping(ptv, dti, JsonTypeInfo.As.WRAPPER_ARRAY);
public ObjectMapper
activateDefaultTyping(PolymorphicTypeValidator
Validator used to verify that actual subtypes to deserialize are valid against whatever criteria validator uses: important in case where untrusted content is deserialized.
ptv
,
ObjectMapper.DefaultTyping
Defines kinds of types for which additional type information is added; see DefaultTyping for more information.
applicability
,
JsonTypeInfo.As includeAs)

Method for enabling automatic inclusion of type information ("Default Typing"), needed for proper deserialization of polymorphic types (unless types have been annotated with com.fasterxml.jackson.annotation.JsonTypeInfo).

public ObjectMapper
activateDefaultTypingAsProperty(PolymorphicTypeValidator
Validator used to verify that actual subtypes to deserialize are valid against whatever criteria validator uses: important in case where untrusted content is deserialized.
ptv
,
ObjectMapper.DefaultTyping
Defines kinds of types for which additional type information is added; see DefaultTyping for more information.
applicability
,
String
Name of property used for including type id for polymorphic values.
propertyName
)

Method for enabling automatic inclusion of type information ("Default Typing") -- needed for proper deserialization of polymorphic types (unless types have been annotated with com.fasterxml.jackson.annotation.JsonTypeInfo) -- using "As.PROPERTY" inclusion mechanism and specified property name to use for inclusion (default being "@class" since default type information always uses class name as type identifier)

Note

choice of PolymorphicTypeValidator to pass is critical for security as allowing all subtypes can be risky for untrusted content.

public ObjectMapper
addHandler(DeserializationProblemHandler h)

Method for adding specified DeserializationProblemHandler to be used for handling specific problems during deserialization.

public ObjectMapper
addMixIn(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 to use for adding mix-in annotations to use for augmenting specified class or interface.

public final void
addMixInAnnotations(Class<?> target, Class<?> mixinSource)
Deprecated Since 2.5: replaced by a fluent form of the method; addMixIn(Class, Class).

public boolean

Returns:

True if mapper can find a serializer for instances of given class (potentially serializable), false otherwise (not serializable)
canDeserialize
(JavaType type)
Deprecated Since 2.18 use discouraged; method to be removed from Jackson 3.0

Method that can be called to check whether mapper thinks it could deserialize an Object of given type.

public boolean
canDeserialize(JavaType type, AtomicReference<Throwable> cause)
Deprecated Since 2.18 use discouraged; method to be removed from Jackson 3.0

Method similar to canDeserialize(JavaType) but that can return actual Throwable that was thrown when trying to construct serializer: this may be useful in figuring out what the actual problem is.

public boolean

Returns:

True if mapper can find a serializer for instances of given class (potentially serializable), false otherwise (not serializable)
canSerialize
(Class<?> type)
Deprecated Since 2.18 use discouraged; method to be removed from Jackson 3.0

Method that can be called to check whether mapper thinks it could serialize an instance of given Class.

public boolean
canSerialize(Class<?> type, AtomicReference<Throwable> cause)
Deprecated Since 2.18 use discouraged; method to be removed from Jackson 3.0

Method similar to canSerialize(Class) but that can return actual Throwable that was thrown when trying to construct serializer: this may be useful in figuring out what the actual problem is.

public ObjectMapper
clearProblemHandlers()

Method for removing all registered DeserializationProblemHandlers instances from this mapper.

public MutableCoercionConfig
coercionConfigDefaults()

Accessor for MutableCoercionConfig through which default (fallback) coercion configurations can be changed.

public MutableCoercionConfig
coercionConfigFor(LogicalType logicalType)

Accessor for MutableCoercionConfig through which coercion configuration for specified logical target type can be set.

public MutableCoercionConfig
coercionConfigFor(Class<?> physicalType)

Accessor for MutableCoercionConfig through which coercion configuration for specified physical target type can be set.

public MutableConfigOverride
configOverride(Class<?> type)

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 ObjectMapper
configure(MapperFeature f, boolean state)
Deprecated Since 2.13 use JsonMapper.builder().configure(...)

public ObjectMapper
configure(SerializationFeature f, boolean state)

Method for changing state of an on/off serialization feature for this object mapper.

public ObjectMapper
configure(DeserializationFeature f, boolean state)

Method for changing state of an on/off deserialization feature for this object mapper.

public ObjectMapper
configure(DatatypeFeature f, boolean state)

Method for changing state of an on/off datatype-specific feature for this object mapper.

public ObjectMapper
configure(JsonParser.Feature f, boolean state)

Method for changing state of specified com.fasterxml.jackson.core.JsonParser.Features for parser instances this object mapper creates.

public ObjectMapper
configure(JsonGenerator.Feature f, boolean state)

Method for changing state of an on/off JsonGenerator feature for generator instances this object mapper creates.

public JavaType
constructType(Type t)

Convenience method for constructing JavaType out of given type (typically java.lang.Class), but without explicit context.

public JavaType
constructType(TypeReference<?> typeRef)

Convenience method for constructing JavaType out of given type reference.

public <T> T
convertValue(Object fromValue, Class<T> toValueType)

Convenience method for doing two-step conversion from given value, into instance of given value type, by writing value into temporary buffer and reading from the buffer into specified target type.

public <T> T
public <T> T
public ObjectMapper
copy()

Method for creating a new ObjectMapper instance that has same initial configuration as this instance.

public ObjectMapper

Returns:

ObjectMapper
copyWith
(JsonFactory
JsonFactory to be used.
factory
)

Method for creating a new ObjectMapper.

public ArrayNode
createArrayNode()

Implements abstract com.fasterxml.jackson.core.ObjectCodec.createArrayNode.

Note

return type is co-variant, as basic ObjectCodec abstraction cannot refer to concrete node types (as it's part of core package, whereas impls are part of mapper package)

protected DefaultDeserializationContext
createDeserializationContext(JsonParser p, DeserializationConfig cfg)

Internal helper method called to create an instance of DeserializationContext for deserializing a single root value.

public JsonGenerator
createGenerator(OutputStream out)

Factory method for constructing properly initialized JsonGenerator to write content using specified OutputStream.

public JsonGenerator
createGenerator(OutputStream out, JsonEncoding enc)

Factory method for constructing properly initialized JsonGenerator to write content using specified OutputStream and encoding.

public JsonGenerator
createGenerator(Writer w)

Factory method for constructing properly initialized JsonGenerator to write content using specified Writer.

public JsonGenerator
createGenerator(File outputFile, JsonEncoding enc)

Factory method for constructing properly initialized JsonGenerator to write content to specified File, using specified encoding.

public JsonGenerator
createGenerator(DataOutput out)

Factory method for constructing properly initialized JsonGenerator to write content using specified DataOutput.

public JsonParser
createNonBlockingByteArrayParser()

Factory method for constructing properly initialized JsonParser to read content using non-blocking (asynchronous) mode.

public ObjectNode
createObjectNode()

Implements abstract com.fasterxml.jackson.core.ObjectCodec.createObjectNode.

Note

return type is co-variant, as basic ObjectCodec abstraction cannot refer to concrete node types (as it's part of core package, whereas impls are part of mapper package)

public JsonParser
createParser(File src)

Factory method for constructing properly initialized JsonParser to read content from specified File.

public JsonParser
createParser(URL src)

Factory method for constructing properly initialized JsonParser to read content from specified File.

public JsonParser
createParser(InputStream in)

Factory method for constructing properly initialized JsonParser to read content using specified InputStream.

public JsonParser
createParser(Reader r)

Factory method for constructing properly initialized JsonParser to read content using specified Reader.

public JsonParser
createParser(byte[] content)

Factory method for constructing properly initialized JsonParser to read content from specified byte array.

public JsonParser
createParser(byte[] content, int offset, int len)

Factory method for constructing properly initialized JsonParser to read content from specified byte array.

public JsonParser
createParser(String content)

Factory method for constructing properly initialized JsonParser to read content from specified String.

public JsonParser
createParser(char[] content)

Factory method for constructing properly initialized JsonParser to read content from specified character array Parser is not managed (or "owned") by ObjectMapper: caller is responsible for properly closing it once content reading is complete.

public JsonParser
createParser(char[] content, int offset, int len)

Factory method for constructing properly initialized JsonParser to read content from specified character array.

public JsonParser
createParser(DataInput content)

Factory method for constructing properly initialized JsonParser to read content using specified DataInput.

public ObjectMapper
deactivateDefaultTyping()

Method for disabling automatic inclusion of type information; if so, only explicitly annotated types (ones with com.fasterxml.jackson.annotation.JsonTypeInfo) will have additional embedded type information.

protected ClassIntrospector
defaultClassIntrospector()

Overridable helper method used to construct default ClassIntrospector to use.

public ObjectMapper
disable(MapperFeature... f)
Deprecated Since 2.13 use JsonMapper.builder().disable(...)

public ObjectMapper
disable(SerializationFeature f)

Method for disabling specified DeserializationConfig features.

public ObjectMapper
disable(SerializationFeature first, SerializationFeature... f)

Method for disabling specified DeserializationConfig features.

public ObjectMapper
disable(DeserializationFeature feature)

Method for disabling specified DeserializationConfig features.

public ObjectMapper
disable(DeserializationFeature first, DeserializationFeature... f)

Method for disabling specified DeserializationConfig features.

public ObjectMapper
disable(JsonParser.Feature... features)

Method for disabling specified com.fasterxml.jackson.core.JsonParser.Features for parser instances this object mapper creates.

public ObjectMapper
disable(JsonGenerator.Feature... features)

Method for disabling specified com.fasterxml.jackson.core.JsonGenerator.Features for parser instances this object mapper creates.

public ObjectMapper
disableDefaultTyping()
Deprecated Since 2.10 use deactivateDefaultTyping instead

public ObjectMapper
enable(MapperFeature... f)
Deprecated Since 2.13 use JsonMapper.builder().enable(...)

public ObjectMapper
enable(SerializationFeature f)

Method for enabling specified DeserializationConfig feature.

public ObjectMapper
enable(SerializationFeature first, SerializationFeature... f)

Method for enabling specified DeserializationConfig features.

public ObjectMapper
enable(DeserializationFeature feature)

Method for enabling specified DeserializationConfig features.

public ObjectMapper
enable(DeserializationFeature first, DeserializationFeature... f)

Method for enabling specified DeserializationConfig features.

public ObjectMapper
enable(JsonParser.Feature... features)

Method for enabling specified com.fasterxml.jackson.core.JsonParser.Features for parser instances this object mapper creates.

public ObjectMapper
enable(JsonGenerator.Feature... features)

Method for enabling specified com.fasterxml.jackson.core.JsonGenerator.Features for parser instances this object mapper creates.

public ObjectMapper
public ObjectMapper
public ObjectMapper
public ObjectMapper
public ObjectMapper
findAndRegisterModules()

Convenience method that is functionally equivalent to: mapper.registerModules(mapper.findModules());

As with findModules(), no caching is done for modules, so care needs to be taken to either create and share a single mapper instance; or to cache introspected set of modules.

public Class<?>
public static List<Module>
findModules()

Method for locating available methods, using JDK ServiceLoader facility, along with module-provided SPI.

public static List<Module>
findModules(ClassLoader classLoader)

Method for locating available methods, using JDK ServiceLoader facility, along with module-provided SPI.

public JsonSchema

Returns:

Constructed JSON schema.
generateJsonSchema
(Class<?>
The class to generate schema for
t
)
Deprecated Since 2.6 use external JSON Schema generator (jackson-module-jsonSchema) (which under the hood calls acceptJsonFormatVisitor(JavaType, JsonFormatVisitorWrapper))

Generate Json-schema instance for specified class.

public DateFormat
public DeserializationConfig
getDeserializationConfig()

Method that returns the shared default DeserializationConfig object that defines configuration settings for deserialization.

public DeserializationContext
public JsonFactory
getFactory()

Overrides com.fasterxml.jackson.core.ObjectCodec.getFactory.

Accessor for finding underlying data format factory (JsonFactory) codec will use for data binding.

public InjectableValues
public JsonNodeFactory
getNodeFactory()

Method that can be used to get hold of JsonNodeFactory that this mapper will use when directly constructing root JsonNode instances for Trees.

public PolymorphicTypeValidator
getPolymorphicTypeValidator()

Accessor for configured PolymorphicTypeValidator used for validating polymorphic subtypes used with explicit polymorphic types (annotation-based), but NOT one with "default typing" (see activateDefaultTyping(PolymorphicTypeValidator) for details).

public PropertyNamingStrategy
public Set<Object>
getRegisteredModuleIds()

The set of Module typeIds that are registered in this ObjectMapper, if (and only if!) MapperFeature#IGNORE_DUPLICATE_MODULE_REGISTRATIONS is enabled AND module being added returns non-null value for its Module#getTypeId().

public SerializationConfig
getSerializationConfig()

Method that returns the shared default SerializationConfig object that defines configuration settings for serialization.

public SerializerFactory
getSerializerFactory()

Method for getting current SerializerFactory.

public SerializerProvider
getSerializerProvider()

Accessor for the "blueprint" (or, factory) instance, from which instances are created by calling DefaultSerializerProvider#createInstance.

public SerializerProvider
getSerializerProviderInstance()

Accessor for constructing and returning a SerializerProvider instance that may be used for accessing serializers.

public SubtypeResolver
getSubtypeResolver()

Method for accessing subtype resolver in use.

public TypeFactory
getTypeFactory()

Accessor for getting currently configured TypeFactory instance.

public VisibilityChecker<?>
getVisibilityChecker()

Method for accessing currently configured visibility checker; object used for determining whether given property element (method, field, constructor) can be auto-detected or not.

public boolean
isEnabled(MapperFeature f)

Method for checking whether given MapperFeature is enabled.

public boolean
isEnabled(SerializationFeature f)

Method for checking whether given serialization-specific feature is enabled.

public boolean
isEnabled(DeserializationFeature f)

Method for checking whether given deserialization-specific feature is enabled.

public boolean
public boolean
public boolean
isEnabled(JsonFactory.Feature f)

Convenience method, equivalent to:

  getFactory().isEnabled(f);
public boolean
public boolean
public JsonNode
public int
public JsonNode
public ObjectReader
reader()

Factory method for constructing ObjectReader with default settings.

public ObjectReader
reader(DeserializationFeature feature)

Factory method for constructing ObjectReader with specified feature enabled (compared to settings that this mapper instance has).

public ObjectReader
reader(DeserializationFeature first, DeserializationFeature... other)

Factory method for constructing ObjectReader with specified features enabled (compared to settings that this mapper instance has).

public ObjectReader
reader(JsonNodeFactory nodeFactory)

Factory method for constructing ObjectReader that will use specified JsonNodeFactory for constructing JSON trees.

public ObjectReader
reader(FormatSchema
Schema to pass to parser
schema
)

Factory method for constructing ObjectReader that will pass specific schema object to JsonParser used for reading content.

public ObjectReader
reader(InjectableValues
Injectable values to use
injectableValues
)

Factory method for constructing ObjectReader that will use specified injectable values.

public ObjectReader
reader(Base64Variant defaultBase64)

Factory method for constructing ObjectReader that will use specified Base64 encoding variant for Base64-encoded binary data.

public ObjectReader
reader(ContextAttributes attrs)

Factory method for constructing ObjectReader that will use specified default attributes.

public ObjectReader
reader(JavaType type)
Deprecated Since 2.5, use readerFor(JavaType) instead

public ObjectReader
reader(Class<?> type)
Deprecated Since 2.5, use readerFor(Class) instead

public ObjectReader
reader(TypeReference<?> type)
Deprecated Since 2.5, use readerFor(TypeReference) instead

public ObjectReader
readerFor(JavaType type)

Factory method for constructing ObjectReader that will read or update instances of specified type

public ObjectReader
readerFor(Class<?> type)

Factory method for constructing ObjectReader that will read or update instances of specified type

public ObjectReader
readerFor(TypeReference<?> typeRef)

Factory method for constructing ObjectReader that will read or update instances of specified type

public ObjectReader
readerForArrayOf(Class<?> type)

Factory method for constructing ObjectReader that will read values of a type List<type>.

public ObjectReader
readerForListOf(Class<?> type)

Factory method for constructing ObjectReader that will read or update instances of a type List<type>.

public ObjectReader
readerForMapOf(Class<?> type)

Factory method for constructing ObjectReader that will read or update instances of a type Map<String, type> Functionally same as:

    readerFor(new TypeReference<Map<String, type>>() { });
public ObjectReader
readerForUpdating(Object valueToUpdate)

Factory method for constructing ObjectReader that will update given Object (usually Bean, but can be a Collection or Map as well, but NOT an array) with JSON data.

public ObjectReader
readerWithView(Class<?> view)

Factory method for constructing ObjectReader that will deserialize objects using specified JSON View (filter).

public <T extends TreeNode> T

Returns:

a JsonNode, if valid JSON content found; null if input has no content to bind -- note, however, that if JSON null token is found, it will be represented as a non-null JsonNode (one that returns true for JsonNode#isNull()
readTree
(JsonParser p)

Implements abstract com.fasterxml.jackson.core.ObjectCodec.readTree.

Method to deserialize JSON content as a tree JsonNode.

public JsonNode

Returns:

a JsonNode, if valid JSON content found; null if input has no content to bind -- note, however, that if JSON null token is found, it will be represented as a non-null JsonNode (one that returns true for JsonNode#isNull()
readTree
(InputStream
Input stream used to read JSON content for building the JSON tree.
in
)

Method to deserialize JSON content as tree expressed using set of JsonNode instances.

public JsonNode
readTree(Reader r)

Same as readTree(InputStream) except content accessed through passed-in Reader

public JsonNode
readTree(String content)

Same as readTree(InputStream) except content read from passed-in String

public JsonNode
readTree(byte[] content)

Same as readTree(InputStream) except content read from passed-in byte array.

public JsonNode
readTree(byte[] content, int offset, int len)

Same as readTree(InputStream) except content read from passed-in byte array.

public JsonNode
readTree(File file)

Same as readTree(InputStream) except content read from passed-in File.

public JsonNode
readTree(URL source)

Same as readTree(InputStream) except content read from passed-in URL.

public <T> T
readValue(JsonParser
Parser to use for decoding content to bind
p
,
Class<T>
Java value type to bind content to
valueType
)

Implements abstract com.fasterxml.jackson.core.ObjectCodec.readValue.

Method to deserialize JSON content into a non-container type (it can be an array type, however): typically a bean, array or a wrapper type (like java.lang.Boolean).

public <T> T
readValue(JsonParser
Parser to use for decoding content to bind
p
,
TypeReference<T>
Java value type to bind content to
valueTypeRef
)

Implements abstract com.fasterxml.jackson.core.ObjectCodec.readValue.

Method to deserialize JSON content into a Java type, reference to which is passed as argument.

public final <T> T
readValue(JsonParser
Parser to use for decoding content to bind
p
,
ResolvedType
Java value type to bind content to
valueType
)

Implements abstract com.fasterxml.jackson.core.ObjectCodec.readValue.

Method to deserialize JSON content into a Java type, reference to which is passed as argument.

public <T> T
readValue(JsonParser p, JavaType valueType)

Type-safe overloaded method, basically alias for readValue(JsonParser, Class).

public <T> T
readValue(File src, Class<T> valueType)

Method to deserialize JSON content from given file into given Java type.

public <T> T
readValue(File src, TypeReference<T> valueTypeRef)

Method to deserialize JSON content from given file into given Java type.

public <T> T
readValue(File src, JavaType valueType)

Method to deserialize JSON content from given file into given Java type.

public <T> T
readValue(URL src, Class<T> valueType)

Method to deserialize JSON content from given resource into given Java type.

public <T> T
readValue(URL src, TypeReference<T> valueTypeRef)

Same as readValue(java.net.URL, Class) except that target specified by TypeReference.

public <T> T
readValue(URL src, JavaType valueType)

Same as readValue(java.net.URL, Class) except that target specified by JavaType.

public <T> T
readValue(String content, Class<T> valueType)

Method to deserialize JSON content from given JSON content String.

public <T> T
readValue(String content, TypeReference<T> valueTypeRef)

Method to deserialize JSON content from given JSON content String.

public <T> T
readValue(String content, JavaType valueType)

Method to deserialize JSON content from given JSON content String.

public <T> T
readValue(Reader src, Class<T> valueType)

public <T> T
readValue(Reader src, TypeReference<T> valueTypeRef)

public <T> T
readValue(Reader src, JavaType valueType)

public <T> T
readValue(InputStream src, Class<T> valueType)

public <T> T
readValue(InputStream src, TypeReference<T> valueTypeRef)

public <T> T
readValue(InputStream src, JavaType valueType)

public <T> T
readValue(byte[] src, Class<T> valueType)

public <T> T
readValue(byte[] src, int offset, int len, Class<T> valueType)

public <T> T
readValue(byte[] src, TypeReference<T> valueTypeRef)

public <T> T
readValue(byte[] src, int offset, int len, TypeReference<T> valueTypeRef)

public <T> T
readValue(byte[] src, JavaType valueType)

public <T> T
readValue(byte[] src, int offset, int len, JavaType valueType)

public <T> T
readValue(DataInput src, Class<T> valueType)

public <T> T
readValue(DataInput src, JavaType valueType)

public <T> MappingIterator<T>
readValues(JsonParser
Parser to use for decoding content to bind
p
,
ResolvedType
Java value type to bind content to
valueType
)

Implements abstract com.fasterxml.jackson.core.ObjectCodec.readValues.

Convenience method, equivalent in function to:

   readerFor(valueType).readValues(p);
public <T> MappingIterator<T>
readValues(JsonParser p, JavaType valueType)

Convenience method, equivalent in function to:

   readerFor(valueType).readValues(p);
public <T> MappingIterator<T>
readValues(JsonParser
Parser to use for decoding content to bind
p
,
Class<T>
Java value type to bind content to
valueType
)

Implements abstract com.fasterxml.jackson.core.ObjectCodec.readValues.

Convenience method, equivalent in function to:

   readerFor(valueType).readValues(p);
public <T> MappingIterator<T>
readValues(JsonParser
Parser to use for decoding content to bind
p
,
TypeReference<T>
Java value type to bind content to
valueTypeRef
)

Implements abstract com.fasterxml.jackson.core.ObjectCodec.readValues.

Method for reading sequence of Objects from parser stream.

public ObjectMapper
registerModule(Module
Module to register
module
)

Method for registering a module that can extend functionality provided by this mapper; for example, by adding providers for custom serializers and deserializers.

public ObjectMapper
registerModules(Module... modules)

Convenience method for registering specified modules in order; functionally equivalent to:

   for (Module module : modules) {
      registerModule(module);
   }
public ObjectMapper
registerModules(Iterable<? extends Module> modules)

Convenience method for registering specified modules in order; functionally equivalent to:

   for (Module module : modules) {
      registerModule(module);
   }
public void
registerSubtypes(Class<?>... classes)

Method for registering specified class as a subtype, so that typename-based resolution can link supertypes to subtypes (as an alternative to using annotations).

public void
registerSubtypes(NamedType... types)

Method for registering specified class as a subtype, so that typename-based resolution can link supertypes to subtypes (as an alternative to using annotations).

public void
private static <T> ServiceLoader<T>
secureGetServiceLoader(final Class<T> clazz, final ClassLoader classLoader)

public ObjectMapper
setAccessorNaming(AccessorNamingStrategy.Provider s)

Method for setting custom accessor naming strategy to use.

public ObjectMapper
setAnnotationIntrospector(AnnotationIntrospector ai)

Method for setting AnnotationIntrospector used by this mapper instance for both serialization and deserialization.

public ObjectMapper
setAnnotationIntrospectors(AnnotationIntrospector
AnnotationIntrospector to use for configuring serialization
serializerAI
,
AnnotationIntrospector
AnnotationIntrospector to use for configuring deserialization
deserializerAI
)

Method for changing AnnotationIntrospector instances used by this mapper instance for serialization and deserialization, specifying them separately so that different introspection can be used for different aspects

public ObjectMapper

Returns:

This mapper, for convenience to allow chaining
setBase64Variant
(Base64Variant
Base64 variant to use
v
)

Method that will configure default Base64Variant that byte[] serializers and deserializers will use.

public ObjectMapper
setCacheProvider(CacheProvider
Cache provider for this mapper to use
cacheProvider
)

Method for specifying CacheProvider instance, to provide Cache instances to be used in components downstream.

public ObjectMapper
setConfig(DeserializationConfig config)

Method that allows overriding of the underlying DeserializationConfig object.

public ObjectMapper
setConfig(SerializationConfig config)

Method that allows overriding of the underlying SerializationConfig object, which contains serialization-specific configuration settings.

public ObjectMapper
setConstructorDetector(ConstructorDetector cd)

Method for specifying ConstructorDetector to use for determining some aspects of creator auto-detection (specifically auto-detection of constructor, and in particular behavior with single-argument constructors).

public ObjectMapper
setDateFormat(DateFormat dateFormat)

Method for configuring the default DateFormat to use when serializing time values as Strings, and deserializing from JSON Strings.

public ObjectMapper
setDefaultAttributes(ContextAttributes attrs)

Note

preferred way to set the defaults is to use Builder style construction, see com.fasterxml.jackson.databind.json.JsonMapper#builder (and MapperBuilder#defaultAttributes).

public ObjectMapper
public ObjectMapper
setDefaultMergeable(Boolean b)

Method for setting default Setter configuration, regarding things like merging, null-handling; used for properties for which there are no per-type or per-property overrides (via annotations or config overrides).

public ObjectMapper

Returns:

This mapper, useful for call-chaining
setDefaultPrettyPrinter
(PrettyPrinter
Pretty printer to use by default.
pp
)

Method for specifying PrettyPrinter to use when "default pretty-printing" is enabled (by enabling SerializationFeature#INDENT_OUTPUT)

public ObjectMapper
setDefaultPropertyInclusion(JsonInclude.Value incl)

Method for setting default POJO property inclusion strategy for serialization, applied for all properties for which there are no per-type or per-property overrides (via annotations or config overrides).

public ObjectMapper
setDefaultPropertyInclusion(JsonInclude.Include incl)

Short-cut for:

  setDefaultPropertyInclusion(JsonInclude.Value.construct(incl, incl));
public ObjectMapper
setDefaultSetterInfo(JsonSetter.Value v)

Method for setting default Setter configuration, regarding things like merging, null-handling; used for properties for which there are no per-type or per-property overrides (via annotations or config overrides).

public ObjectMapper
setDefaultTyping(TypeResolverBuilder<?>
Type information inclusion handler
typer
)

Method for enabling automatic inclusion of type information ("Default Typing"), using specified handler object for determining which types this affects, as well as details of how information is embedded.

public ObjectMapper
setDefaultVisibility(JsonAutoDetect.Value vis)

Method for setting auto-detection visibility definition defaults, which are in effect unless overridden by annotations (like JsonAutoDetect) or per-type visibility overrides.

public ObjectMapper
setFilterProvider(FilterProvider filterProvider)

Method for configuring this mapper to use specified FilterProvider for mapping Filter Ids to actual filter instances.

public void
setFilters(FilterProvider filterProvider)
Deprecated Since 2.6, use setFilterProvider instead (allows chaining)

public Object
setHandlerInstantiator(HandlerInstantiator
Instantiator to use; if null, use the default implementation
hi
)

Method for configuring HandlerInstantiator to use for creating instances of handlers (such as serializers, deserializers, type and type id resolvers), given a class.

public ObjectMapper
setInjectableValues(InjectableValues injectableValues)

Method for configuring InjectableValues which used to find values to inject.

public ObjectMapper
setLocale(Locale l)

Method for overriding default locale to use for formatting.

public void
setMixInAnnotations(Map<Class<?>, Class<?>> sourceMixins)
Deprecated Since 2.5: replaced by a fluent form of the method; setMixIns.

public ObjectMapper
setMixInResolver(ClassIntrospector.MixInResolver resolver)

Method that can be called to specify given resolver for locating mix-in classes to use, overriding directly added mappings.

public ObjectMapper
setMixIns(Map<Class<?>, Class<?>> sourceMixins)

Method to use for defining mix-in annotations to use for augmenting annotations that processable (serializable / deserializable) classes have.

public ObjectMapper
setNodeFactory(JsonNodeFactory f)

Method for specifying JsonNodeFactory to use for constructing root level tree nodes (via method createObjectNode

public ObjectMapper
setPolymorphicTypeValidator(PolymorphicTypeValidator ptv)

Method for specifying PolymorphicTypeValidator to use for validating polymorphic subtypes used with explicit polymorphic types (annotation-based), but NOT one with "default typing" (see activateDefaultTyping(PolymorphicTypeValidator) for details).

public ObjectMapper
public ObjectMapper
setPropertyNamingStrategy(PropertyNamingStrategy s)

Method for setting custom property naming strategy to use.

public ObjectMapper
setSerializationInclusion(JsonInclude.Include incl)

Convenience method, equivalent to calling:

  setPropertyInclusion(JsonInclude.Value.construct(incl, incl));
public ObjectMapper
setSerializerFactory(SerializerFactory f)

Method for setting specific SerializerFactory to use for constructing (bean) serializers.

public ObjectMapper
setSerializerProvider(DefaultSerializerProvider p)

Method for setting "blueprint" SerializerProvider instance to use as the base for actual provider instances to use for handling caching of JsonSerializer instances.

public ObjectMapper
setSubtypeResolver(SubtypeResolver str)

Method for setting custom subtype resolver to use.

public ObjectMapper
setTimeZone(TimeZone tz)

Method for overriding default TimeZone to use for formatting.

public ObjectMapper
setTypeFactory(TypeFactory f)

Method that can be used to override TypeFactory instance used by this mapper.

public ObjectMapper
setVisibility(VisibilityChecker<?> vc)

Method for setting currently configured default VisibilityChecker, object used for determining whether given property element (method, field, constructor) can be auto-detected or not.

public ObjectMapper

Returns:

Modified mapper instance (that is, "this"), to allow chaining of configuration calls
setVisibility
(PropertyAccessor
Type of property descriptor affected (field, getter/isGetter, setter, creator)
forMethod
,
JsonAutoDetect.Visibility
Minimum visibility to require for the property descriptors of type
visibility
)

Convenience method that allows changing configuration for underlying VisibilityCheckers, to change details of what kinds of properties are auto-detected.

public void
public JsonFactory

Returns:

JsonFactory that this mapper uses when it needs to construct Json parser and generators
tokenStreamFactory
()

Method that can be used to get hold of JsonFactory that this mapper uses if it needs to construct JsonParsers and/or JsonGenerators.

public JsonParser
treeAsTokens(TreeNode
Root node of the tree that resulting parser will read from
n
)

Implements abstract com.fasterxml.jackson.core.ObjectCodec.treeAsTokens.

Method for constructing a JsonParser out of JSON tree representation.

public <T> T
treeToValue(TreeNode
Tree to convert
n
,
Class<T>
Java target value type to convert content to
valueType
)

Implements abstract com.fasterxml.jackson.core.ObjectCodec.treeToValue.

Convenience conversion method that will bind data given JSON tree contains into specific value (usually bean) type.

public <T> T
treeToValue(TreeNode n, JavaType valueType)

Same as treeToValue(TreeNode, Class) but target type specified using fully resolved JavaType.

public <T> T
treeToValue(TreeNode n, TypeReference<T> toValueTypeRef)

Same as treeToValue(TreeNode, JavaType) but target type specified using fully resolved TypeReference.

public <T> T

Returns:

Either the first argument (`valueToUpdate`), if it is mutable; or a result of creating new instance that is result of "merging" values (for example, "updating" a Java array will create a new array)
updateValue
(T
Object to update
valueToUpdate
,
Object
Object to conceptually serialize and merge into value to update; can be thought of as a provider for overrides to apply.
overrides
)

Convenience method similar to convertValue(Object, JavaType) but one in which

Implementation is approximately as follows:

  1. Serialize `updateWithValue` into TokenBuffer
  2. Construct ObjectReader with `valueToUpdate` (using readerForUpdating(Object))
  3. Construct JsonParser (using TokenBuffer#asParser())
  4. Update using ObjectReader#readValue(JsonParser).
  5. Return `valueToUpdate`
public <
Actual node type; usually either basic JsonNode or com.fasterxml.jackson.databind.node.ObjectNode
T extends JsonNode
>
T

Returns:

(non-null) Root node of the resulting content tree: in case of null value node for which JsonNode#isNull() returns true.
valueToTree
(Object
Java value to convert
fromValue
)

Method that is reverse of treeToValue: it will convert given Java value (usually bean) into its equivalent Tree mode JsonNode representation.

public Version
version()

Implements abstract com.fasterxml.jackson.core.ObjectCodec.version.

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

Method that will return version information stored in and read from jar that contains this class.

public ObjectWriter
writer()

Convenience method for constructing ObjectWriter with default settings.

public ObjectWriter
writer(SerializationFeature feature)

Factory method for constructing ObjectWriter with specified feature enabled (compared to settings that this mapper instance has).

public ObjectWriter
writer(SerializationFeature first, SerializationFeature... other)

Factory method for constructing ObjectWriter with specified features enabled (compared to settings that this mapper instance has).

public ObjectWriter
writer(DateFormat df)

Factory method for constructing ObjectWriter that will serialize objects using specified DateFormat; or, if null passed, using timestamp (64-bit number.

public ObjectWriter
writer(PrettyPrinter pp)

Factory method for constructing ObjectWriter that will serialize objects using specified pretty printer for indentation (or if null, no pretty printer)

public ObjectWriter
writer(FilterProvider filterProvider)

Factory method for constructing ObjectWriter that will serialize objects using specified filter provider.

public ObjectWriter
writer(FormatSchema
Schema to pass to generator
schema
)

Factory method for constructing ObjectWriter that will pass specific schema object to JsonGenerator used for writing content.

public ObjectWriter
writer(Base64Variant defaultBase64)

Factory method for constructing ObjectWriter that will use specified Base64 encoding variant for Base64-encoded binary data.

public ObjectWriter
writer(CharacterEscapes escapes)

Factory method for constructing ObjectReader that will use specified character escaping details for output.

public ObjectWriter
writer(ContextAttributes attrs)

Factory method for constructing ObjectWriter that will use specified default attributes.

public ObjectWriter
writerFor(Class<?> rootType)

Factory method for constructing ObjectWriter that will serialize objects using specified root type, instead of actual runtime type of value.

public ObjectWriter
writerFor(TypeReference<?> rootType)

Factory method for constructing ObjectWriter that will serialize objects using specified root type, instead of actual runtime type of value.

public ObjectWriter
writerFor(JavaType rootType)

Factory method for constructing ObjectWriter that will serialize objects using specified root type, instead of actual runtime type of value.

public ObjectWriter
writerWithDefaultPrettyPrinter()

Factory method for constructing ObjectWriter that will serialize objects using the default pretty printer for indentation

public ObjectWriter
writerWithType(Class<?> rootType)
Deprecated Since 2.5, use writerFor(Class) instead

public ObjectWriter
writerWithType(TypeReference<?> rootType)
Deprecated Since 2.5, use writerFor(TypeReference) instead

public ObjectWriter
writerWithType(JavaType rootType)
Deprecated Since 2.5, use writerFor(JavaType) instead

public ObjectWriter
writerWithView(Class<?> serializationView)

Factory method for constructing ObjectWriter that will serialize objects using specified JSON View (filter).

public void
writeTree(JsonGenerator
Generator to use for serializing value
g
,
TreeNode
Tree to serialize
rootNode
)

Implements abstract com.fasterxml.jackson.core.ObjectCodec.writeTree.

Method for serializing JSON content from given Tree instance, using specified generator.

public void
writeTree(JsonGenerator g, JsonNode rootNode)

Method to serialize given JSON Tree, using generator provided.

public void
writeValue(JsonGenerator
Generator to use for serializing value
g
,
Object
Value to serialize
value
)

Implements abstract com.fasterxml.jackson.core.ObjectCodec.writeValue.

Method that can be used to serialize any Java value as JSON output, using provided JsonGenerator.

public void
writeValue(File resultFile, Object value)

Method that can be used to serialize any Java value as JSON output, written to File provided.

public void
writeValue(OutputStream out, Object value)

Method that can be used to serialize any Java value as JSON output, using output stream provided (using encoding JsonEncoding#UTF8).

public void
public void
writeValue(Writer w, Object value)

Method that can be used to serialize any Java value as JSON output, using Writer provided.

public byte[]
writeValueAsBytes(Object value)

Method that can be used to serialize any Java value as a byte array.

public String
writeValueAsString(Object value)

Method that can be used to serialize any Java value as a String.

Inherited from com.fasterxml.jackson.core.ObjectCodec:
getJsonFactory