JsonNode), as well as writing Java Objects and trees as JSON. Reading and writing (as well as related additional functionality) is accessed through
ObjectWriterclasses. 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
ObjectMapperwith different underlying streaming parser, generator implementation.
The main starting point for operations is
which can be used either directly (via multiple overloaded
writeTree methods, or it can be used as a configurable factory for constructing
fully immutable, thread-safe and reusable
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
- Type introspection needed for things like generation of Schemas (like JSON Schema, Avro Schema, or protoc
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
JsonPointerexpression: int age = root.at("/personal/age").getValueAsInt();
Interface Summary Interface Description BeanPropertyBean 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). JsonSerializable Module.SetupContextInterface Jackson exposes to modules for purpose of registering extended functionality.
Class Summary Class Description AbstractTypeResolverDefines interface for resolvers that can resolve abstract types into concrete ones; either by using static mappings, or possibly by materializing implementations dynamically. AnnotationIntrospectorAbstract class that defines API used for introspecting annotation-based configuration for serialization and deserialization. AnnotationIntrospector.ReferencePropertyValue type used with managed and back references; contains type and logic name, used to link related references BeanDescriptionBasic container for information gathered by
ClassIntrospectorto help in constructing serializers and deserializers.
BeanProperty.BogusAlternative "Null" implementation that can be used in cases where a non-null
BeanProperty.StdSimple stand-alone implementation, useful as a placeholder or base class for more complex implementations. DatabindContext DeserializationConfigObject that contains baseline configuration for deserialization process. DeserializationContextContext for the process of deserialization a single root-level value. InjectableValuesAbstract class that defines API for objects that provide value to "inject" during deserialization. InjectableValues.StdSimple standard implementation which uses a simple Map to store values to inject, identified by simple String keys. JavaTypeBase class for type token classes used both to contain information and as keys for deserializers. JsonDeserializer<T> JsonDeserializer.NoneThis marker class is only to be used with annotations, to indicate that no deserializer is configured. JsonMappingException.ReferenceSimple bean class used to contain references. JsonNodeBase class for all JSON nodes, which form the basis of JSON Tree Model that Jackson implements. JsonSerializable.BaseBase class with minimal implementation, as well as couple of extension methods that core Jackson databinding makes use of. JsonSerializer<T> JsonSerializer.NoneThis marker class is only to be used with annotations, to indicate that no serializer is configured. KeyDeserializerAbstract class that defines API used for deserializing JSON content field names into Java Map keys. KeyDeserializer.NoneThis marker class is only to be used with annotations, to indicate that no deserializer is configured. MappingIterator<T>Iterator exposed by
ObjectMapperwhen binding sequence of objects.
MappingJsonFactory ModuleSimple interface for extensions that can be registered with
ObjectMapperto provide a well-defined set of extensions to default functionality; such as support for new data types.
ObjectMapperObjectMapper 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.
TypeResolverBuilderthat provides type resolver builders used with so-called "default typing" (see
ObjectReaderBuilder 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). ObjectWriterBuilder object that can be used for per-serialization configuration of serialization parameters, such as JSON View and root type to use. ObjectWriter.GeneratorSettingsHelper class used for containing settings specifically related to (re)configuring
JsonGeneratorconstructed for writing output.
ObjectWriter.PrefetchAs a minor optimization, we will make an effort to pre-fetch a serializer, or at least relevant
TypeSerializer, if given enough information.
PropertyMetadataSimple container class used for storing "additional" metadata about properties. PropertyMetadata.MergeInfoHelper class used for containing information about expected merge information for this property, if merging is expected. PropertyNameSimple value class used for containing names of properties as defined by annotations (and possibly other configuration sources). PropertyNamingStrategiesContainer for standard
PropertyNamingStrategyimplementations and singleton instances.
PropertyNamingStrategies.KebabCaseStrategyNaming strategy similar to
PropertyNamingStrategies.SnakeCaseStrategy, but instead of underscores as separators, uses hyphens.
PropertyNamingStrategies.LowerCamelCaseStrategy"No-operation" strategy that is equivalent to not specifying any strategy: will simply return suggested standard bean naming as-is. PropertyNamingStrategies.LowerCaseStrategySimple strategy where external name simply only uses lower-case characters, and no separators. PropertyNamingStrategies.LowerDotCaseStrategyNaming strategy similar to
PropertyNamingStrategies.KebabCaseStrategy, but instead of hyphens as separators, uses dots.
PropertyNamingStrategies.NamingBaseIntermediate base class for simple implementations PropertyNamingStrategies.SnakeCaseStrategyA
PropertyNamingStrategythat translates typical camel case Java property names to lower case JSON element names, separated by underscores.
PropertyNamingStrategythat translates typical camelCase Java property names to PascalCase JSON element names (i.e., with a capital first letter).
PropertyNamingStrategyClass 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. PropertyNamingStrategy.KebabCaseStrategy Deprecated. PropertyNamingStrategy.LowerCaseStrategy Deprecated. PropertyNamingStrategy.LowerCaseWithUnderscoresStrategy Deprecated.In 2.7 use
PropertyNamingStrategy.LowerDotCaseStrategy Deprecated. PropertyNamingStrategy.PascalCaseStrategy Deprecated.In 2.7 use
PropertyNamingStrategy.PropertyNamingStrategyBase Deprecated.Since 2.12 deprecated. PropertyNamingStrategy.SnakeCaseStrategy Deprecated. PropertyNamingStrategy.UpperCamelCaseStrategy Deprecated. SequenceWriterWriter class similar to
ObjectWriter, except that it can be used for writing sequences of values, not just a single value.
SerializationConfigObject that contains baseline configuration for serialization process. SerializerProvider
Enum Summary Enum Description AnnotationIntrospector.ReferenceProperty.Type DeserializationFeatureEnumeration that defines simple on/off features that affect the way Java objects are deserialized from JSON MapperFeature ObjectMapper.DefaultTypingEnumeration used with
ObjectMapper.activateDefaultTyping(PolymorphicTypeValidator)to specify what kind of types (classes) default typing should be used for.
SerializationFeatureEnumeration that defines simple on/off features that affect the way Java objects are serialized.
Exception Summary Exception Description JsonMappingException RuntimeJsonMappingExceptionWrapper used when interface does not allow throwing a checked