Package com.fasterxml.jackson.databind
package com.fasterxml.jackson.databind
Basic data binding (mapping) functionality that
allows for reading JSON content into Java Objects (POJOs)
and JSON Trees (
JsonNode
), as well as
writing Java Objects and trees as JSON.
Reading and writing (as well as related additional functionality) is accessed through
ObjectMapper
,
ObjectReader
and
ObjectWriter
classes.
In addition to reading and writing JSON content, it is also possible to use the
general databinding functionality for many other data formats, using
Jackson extension modules that provide such support: if so, you typically
simply construct an ObjectMapper
with
different underlying streaming parser, generator implementation.
The main starting point for operations is ObjectMapper
,
which can be used either directly (via multiple overloaded
readValue
,
readTree
,
writeValue
and
writeTree
methods, or it can be used as a configurable factory for constructing
fully immutable, thread-safe and reusable ObjectReader
and ObjectWriter
objects.
In addition to simple reading and writing of JSON as POJOs or JSON trees (represented as
JsonNode
, and configurability needed to change aspects
of reading/writing, mapper contains additional functionality such as:
- Value conversions using
ObjectMapper.convertValue(Object, Class)
,ObjectMapper.valueToTree(Object)
andObjectMapper.treeToValue(com.fasterxml.jackson.core.TreeNode, Class)
methods. - Type introspection needed for things like generation of Schemas (like JSON Schema, Avro Schema, or protoc
definitions), using
ObjectMapper.acceptJsonFormatVisitor(Class, com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitorWrapper)
(note: actual handles are usually provided by various Jackson modules: mapper simply initiates calling of callbacks, based on serializers registered)
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 JsonPointer
expression:
int age = root.at("/personal/age").getValueAsInt();
For more usage, refer to
ObjectMapper
,
ObjectReader
and
ObjectWriter
Javadocs.
-
ClassDescriptionDefines interface for resolvers that can resolve abstract types into concrete ones; either by using static mappings, or possibly by materializing implementations dynamically.Abstract class that defines API used for introspecting annotation-based configuration for serialization and deserialization.Value type used with managed and back references; contains type and logic name, used to link related referencesAdd-on extension used for XML-specific configuration, needed to decouple format module functionality from pluggable introspection functionality (especially JAXB-annotation related one).Basic container for information gathered by
ClassIntrospector
to help in constructing serializers and deserializers.Bean properties are logical entities that represent data that Java objects (POJOs (Plain Old Java Objects), sometimes also called "beans") contain; and that are accessed using accessors (methods like getters and setters, fields, constructor parameters).Alternative "Null" implementation that can be used in cases where a non-nullBeanProperty
is neededSimple stand-alone implementation, useful as a placeholder or base class for more complex implementations.Shared base class forDeserializationContext
andSerializerProvider
, context objects passed through data-binding process.Intermediate base class for all databind level processing problems, as distinct from stream-level problems or I/O issues below.Object that contains baseline configuration for deserialization process.Context for the process of deserialization a single root-level value.Enumeration that defines simple on/off features that affect the way Java objects are deserialized from JSONA container class for implementations of theEnumNamingStrategy
interface.An implementation ofEnumNamingStrategy
that converts enum names in the typical upper snake case format to camel case format.Defines how the string representation of an enum is converted into an external property name for mapping during deserialization.Abstract class that defines API for objects that provide value to "inject" during deserialization.Simple standard implementation which uses a simple Map to store values to inject, identified by simple String keys.Base class for type token classes used both to contain information and as keys for deserializers.Abstract class that defines API used byObjectMapper
(and other chainedJsonDeserializer
s too) to deserialize Objects of arbitrary types from JSON, using providedJsonParser
.This marker class is only to be used with annotations, to indicate that no deserializer is configured.Checked exception used to signal fatal problems with mapping of content, distinct from low-level I/O problems (signaled using simpleIOException
s) or data encoding/decoding problems (signaled withStreamReadException
,StreamWriteException
).Simple bean class used to contain references.Base class for all JSON nodes, which form the basis of JSON Tree Model that Jackson implements.Configuration setting used withJsonNode.withObject(JsonPointer)
method overrides, to indicate which overwrites are acceptable if the path pointer indicates has incompatible nodes (for example, instead of Object node a Null node is encountered).Interface that can be implemented by objects that know how to serialize themselves to JSON, usingJsonGenerator
(andSerializerProvider
if necessary).Base class with minimal implementation, as well as couple of extension methods that core Jackson databinding makes use of.Abstract class that defines API used byObjectMapper
(and other chainedJsonSerializer
s too) to serialize Objects of arbitrary types into JSON, using providedJsonGenerator
.This marker class is only to be used with annotations, to indicate that no serializer is configured.Abstract class that defines API used for deserializing JSON content field names into Java Map keys.This marker class is only to be used with annotations, to indicate that no deserializer is configured.Enumeration that defines simple on/off features to set forObjectMapper
, and accessible (but not changeable) viaObjectReader
andObjectWriter
(as well as through various convenience methods through context objects).Iterator exposed byObjectMapper
when binding sequence of objects.Sub-class ofJsonFactory
that will create a properObjectCodec
to allow seam-less conversions between JSON content and Java objects (POJOs).Simple interface for extensions that can be registered withObjectMapper
to provide a well-defined set of extensions to default functionality; such as support for new data types.Interface Jackson exposes to modules for purpose of registering extended functionality.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.CustomizedTypeResolverBuilder
that provides type resolver builders used with so-called "default typing" (seeObjectMapper.activateDefaultTyping(PolymorphicTypeValidator)
for details).Enumeration used withObjectMapper.activateDefaultTyping(PolymorphicTypeValidator)
to specify what kind of types (classes) default typing should be used for.Builder object that can be used for per-serialization configuration of deserialization parameters, such as root type to use or object to update (instead of constructing new instance).Builder object that can be used for per-serialization configuration of serialization parameters, such as JSON View and root type to use.Helper class used for containing settings specifically related to (re)configuringJsonGenerator
constructed for writing output.As a minor optimization, we will make an effort to pre-fetch a serializer, or at least relevantTypeSerializer
, if given enough information.Simple container class used for storing "additional" metadata about properties.Helper class used for containing information about expected merge information for this property, if merging is expected.Simple value class used for containing names of properties as defined by annotations (and possibly other configuration sources).Container for standardPropertyNamingStrategy
implementations and singleton instances.Naming strategy similar toPropertyNamingStrategies.SnakeCaseStrategy
, but instead of underscores as separators, uses hyphens."No-operation" strategy that is equivalent to not specifying any strategy: will simply return suggested standard bean naming as-is.Simple strategy where external name simply only uses lower-case characters, and no separators.Naming strategy similar toPropertyNamingStrategies.KebabCaseStrategy
, but instead of hyphens as separators, uses dots.Intermediate base class for simple implementationsAPropertyNamingStrategy
that translates typical camel case Java property names to lower case JSON element names, separated by underscores.APropertyNamingStrategy
that translates typical camelCase Java property names to PascalCase JSON element names (i.e., with a capital first letter).APropertyNamingStrategy
that translates an input to the equivalent upper case snake case.Class that defines how names of JSON properties ("external names") are derived from names of POJO methods and fields ("internal names"), in cases where no explicit annotations exist for naming.Deprecated.Deprecated.Since 2.12 usePropertyNamingStrategies.LowerCaseStrategy
instead (see databind#2715 for reason for deprecation)Deprecated.Since 2.12 usePropertyNamingStrategies.LowerDotCaseStrategy
instead (see databind#2715 for reason for deprecation)Deprecated.Since 2.12 deprecated.Deprecated.Since 2.12 usePropertyNamingStrategies.SnakeCaseStrategy
instead (see databind#2715 for reason for deprecation)Deprecated.Since 2.12 usePropertyNamingStrategies.UpperCamelCaseStrategy
instead (see databind#2715 for reason for deprecation)Wrapper used when interface does not allow throwing a checkedJsonMappingException
Writer class similar toObjectWriter
, except that it can be used for writing sequences of values, not just a single value.Object that contains baseline configuration for serialization process.Enumeration that defines simple on/off features that affect the way Java objects are serialized.Class that defines API used byObjectMapper
andJsonSerializer
s to obtain serializers capable of serializing instances of specific types; as well as the default implementation of the functionality.
PropertyNamingStrategies.KebabCaseStrategy
instead (see databind#2715 for reason for deprecation)