- All Implemented Interfaces:
Serializable
,TreeCodec
,Versioned
- Direct Known Subclasses:
JsonMapper
JsonNode
), as well as
related functionality for performing conversions.
In addition to directly reading and writing JSON (and with different underlying
TokenStreamFactory
configuration, other formats), it is also the
mechanism for creating ObjectReader
s and ObjectWriter
s which
offer more advancing reading/writing functionality.
Construction of mapper instances proceeds either via no-arguments constructor
(producing instance with default configuration); or through one of two build
methods.
First build method is the static builder()
on exact type
and second rebuild()
method on an existing mapper.
Former starts with default configuration (same as one that no-arguments constructor
created mapper has), and latter starts with configuration of the mapper it is called
on.
In both cases, after configuration (including addition of JacksonModule
s) is complete,
instance is created by calling MapperBuilder.build()
method.
Mapper (and ObjectReader
s, ObjectWriter
s 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 JsonPointer
expression:
int age = root.at("/personal/age").getValueAsInt();
Mapper instances are fully thread-safe as of Jackson 3.0.
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).
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final DeserializationConfig
Configuration object that defines basic global settings for the serialization processprotected final DeserializationContexts
Factory used for constructing per-callDeserializationContext
s.protected final InjectableValues
Provider for values to inject in deserialized POJOs.protected final ConcurrentHashMap<JavaType,
ValueDeserializer<Object>> We will use a separate main-level Map for keeping track of root-level deserializers.protected final MapperBuilderState
Minimal state retained to allow both re-building (by creating new builder) and JDK serialization of this mapper.protected final SerializationConfig
Configuration object that defines basic global settings for the serialization processprotected final SerializationContexts
Factory used for constructing per-callSerializationContext
s.protected final TokenStreamFactory
Factory used to createJsonParser
andJsonGenerator
instances as necessary.protected final TypeFactory
Specific factory used for creatingJavaType
instances; needed to allow modules to add more custom type handling (mostly to support types of non-Java JVM languages) -
Constructor Summary
ConstructorsModifierConstructorDescriptionDefault constructor, which will construct the default JSON-handlingTokenStreamFactory
as necessary and all other unmodified default settings, and no additional registered modules.ObjectMapper
(TokenStreamFactory streamFactory) Constructs instance that uses specifiedTokenStreamFactory
for constructing necessaryJsonParser
s and/orJsonGenerator
s, but without registering additional modules.protected
ObjectMapper
(MapperBuilder<?, ?> builder) Constructor usually called either byMapperBuilder.build()
or by sub-class constructor: will get all the settings through passed-in builder, including registration of any modules added to builder. -
Method Summary
Modifier and TypeMethodDescriptionprotected final void
_assertNotNull
(String paramName, Object src) protected final void
_configAndWriteValue
(SerializationContextExt prov, JsonGenerator g, Object value) Method called to configure the generator as necessary and then call write functionalityprotected Object
Actual conversion implementation: instead of using existing read and write methods, much of code is inlined.protected DeserializationContextExt
Internal helper method called to create an instance ofDeserializationContext
for deserializing a single root value.protected DeserializationContextExt
protected ValueDeserializer<Object>
_findRootDeserializer
(DeserializationContext ctxt, JavaType valueType) Method called to locate deserializer for the passed root-level value.protected JsonToken
_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 produceObjectReader
instances of proper sub-typeprotected ObjectReader
_newReader
(DeserializationConfig config, JavaType valueType, Object valueToUpdate, FormatSchema schema, InjectableValues injectableValues) Factory method sub-classes must override, to produceObjectReader
instances of proper sub-typeprotected ObjectWriter
_newWriter
(SerializationConfig config) Factory method sub-classes must override, to produceObjectWriter
instances of proper sub-typeprotected ObjectWriter
_newWriter
(SerializationConfig config, FormatSchema schema) Factory method sub-classes must override, to produceObjectWriter
instances of proper sub-typeprotected ObjectWriter
_newWriter
(SerializationConfig config, JavaType rootType, PrettyPrinter pp) Factory method sub-classes must override, to produceObjectWriter
instances of proper sub-typeprotected Object
_readMapAndClose
(DeserializationContextExt ctxt, JsonParser p0, JavaType valueType) protected JsonNode
Similar to_readMapAndClose(tools.jackson.databind.deser.DeserializationContextExt, tools.jackson.core.JsonParser, tools.jackson.databind.JavaType)
but specialized forJsonNode
reading.protected Object
_readValue
(DeserializationContextExt ctxt, JsonParser p, JavaType valueType) Actual implementation of value reading+binding operation.protected SerializationContextExt
Overridable helper method used for constructingSerializationContext
to use for serialization.protected final void
_verifyNoTrailingTokens
(JsonParser p, DeserializationContext ctxt, JavaType bindType) protected void
_verifySchemaType
(FormatSchema schema) protected final void
_writeCloseableValue
(JsonGenerator g, Object value, SerializationConfig cfg) Helper method used when value to serialize isCloseable
and itsclose()
method is to be called right after serialization has been calledvoid
acceptJsonFormatVisitor
(Class<?> type, JsonFormatVisitorWrapper visitor) Method for visiting type hierarchy for given type, using specified visitor.void
acceptJsonFormatVisitor
(TypeReference<?> typeRef, JsonFormatVisitorWrapper visitor) void
acceptJsonFormatVisitor
(JavaType type, JsonFormatVisitorWrapper visitor) Method for visiting type hierarchy for given type, using specified visitor.booleanNode
(boolean b) void
Method that will clear all caches this mapper owns.constructType
(Type type) Convenience method for constructingJavaType
out of given type (typicallyjava.lang.Class
), but without explicit context.constructType
(TypeReference<?> typeReference) Convenience method for constructingJavaType
out of given type reference.<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.<T> T
convertValue
(Object fromValue, TypeReference<T> toValueTypeRef) <T> T
convertValue
(Object fromValue, JavaType toValueType) Note: return type is co-variant, as basicTreeCodec
abstraction cannot refer to concrete node types (as it's part of core package, whereas impls are part of mapper package)Factory method for constructingJsonGenerator
that is properly wired to allow callbacks for serialization: basically constructs aObjectWriteContext
and then callsTokenStreamFactory.createGenerator(ObjectWriteContext,DataOutput)
.createGenerator
(File f, JsonEncoding enc) Factory method for constructingJsonGenerator
that is properly wired to allow callbacks for serialization: basically constructs aObjectWriteContext
and then callsTokenStreamFactory.createGenerator(ObjectWriteContext,File,JsonEncoding)
.Factory method for constructingJsonGenerator
that is properly wired to allow callbacks for serialization: basically constructs aObjectWriteContext
and then callsTokenStreamFactory.createGenerator(ObjectWriteContext,OutputStream)
.createGenerator
(OutputStream out, JsonEncoding enc) Factory method for constructingJsonGenerator
that is properly wired to allow callbacks for serialization: basically constructs aObjectWriteContext
and then callsTokenStreamFactory.createGenerator(ObjectWriteContext,OutputStream,JsonEncoding)
.Factory method for constructingJsonGenerator
that is properly wired to allow callbacks for serialization: basically constructs aObjectWriteContext
and then callsTokenStreamFactory.createGenerator(ObjectWriteContext,Writer)
.createGenerator
(Path path, JsonEncoding enc) Factory method for constructingJsonGenerator
that is properly wired to allow callbacks for serialization: basically constructs aObjectWriteContext
and then callsTokenStreamFactory.createGenerator(ObjectWriteContext,Path,JsonEncoding)
.Factory method for constructing non-blockingJsonParser
that is properly wired to allow configuration access (and, if relevant for parser, callbacks): essentially constructs aObjectReadContext
and then callsTokenStreamFactory.createParser(ObjectReadContext,DataInput)
.Note: return type is co-variant, as basicTreeCodec
abstraction cannot refer to concrete node types (as it's part of core package, whereas impls are part of mapper package)createParser
(byte[] content) Factory method for constructingJsonParser
that is properly wired to allow callbacks for deserialization: basically constructs aObjectReadContext
and then callsTokenStreamFactory.createParser(ObjectReadContext,byte[])
.createParser
(byte[] content, int offset, int len) Factory method for constructingJsonParser
that is properly wired to allow callbacks for deserialization: basically constructs aObjectReadContext
and then callsTokenStreamFactory.createParser(ObjectReadContext,byte[],int,int)
.createParser
(char[] content) Factory method for constructingJsonParser
that is properly wired to allow callbacks for deserialization: basically constructs aObjectReadContext
and then callsTokenStreamFactory.createParser(ObjectReadContext,char[])
.createParser
(char[] content, int offset, int len) Factory method for constructingJsonParser
that is properly wired to allow callbacks for deserialization: basically constructs aObjectReadContext
and then callsTokenStreamFactory.createParser(ObjectReadContext,char[],int,int)
.createParser
(DataInput content) Factory method for constructingJsonParser
that is properly wired to allow callbacks for deserialization: basically constructs aObjectReadContext
and then callsTokenStreamFactory.createParser(ObjectReadContext,DataInput)
.createParser
(File src) Factory method for constructingJsonParser
that is properly wired to allow callbacks for deserialization: basically constructs aObjectReadContext
and then callsTokenStreamFactory.createParser(ObjectReadContext,java.io.File)
.Factory method for constructingJsonParser
that is properly wired to allow callbacks for deserialization: basically constructs aObjectReadContext
and then callsTokenStreamFactory.createParser(ObjectReadContext,InputStream)
.Factory method for constructingJsonParser
that is properly wired to allow callbacks for deserialization: basically constructs aObjectReadContext
and then callsTokenStreamFactory.createParser(ObjectReadContext,Reader)
.createParser
(String content) Factory method for constructingJsonParser
that is properly wired to allow callbacks for deserialization: basically constructs aObjectReadContext
and then callsTokenStreamFactory.createParser(ObjectReadContext,String)
.createParser
(URL src) Factory method for constructingJsonParser
that is properly wired to allow callbacks for deserialization: basically constructs aObjectReadContext
and then callsTokenStreamFactory.createParser(ObjectReadContext,java.net.URL)
.createParser
(Path src) Factory method for constructingJsonParser
that is properly wired to allow callbacks for deserialization: basically constructs aObjectReadContext
and then callsTokenStreamFactory.createParser(ObjectReadContext,Path)
.Accessor for internal configuration object that contains settings for deserialization operations (readValue(...)
methods)
NOTE: Not to be used by application code; needed by some testsMethod that can be used to get hold ofJsonNodeFactory
that this mapper will use when directly constructing rootJsonNode
instances for Trees.Method that may be used to find outJacksonModule
s that were registered when creating this mapper (if any).Accessor for getting currently configuredTypeFactory
instance.boolean
boolean
boolean
boolean
Method for checking whether given deserialization-specific feature is enabled.boolean
Method for checking whether givenMapperFeature
is enabled.boolean
Method for checking whether given serialization-specific feature is enabled.nullNode()
reader()
Factory method for constructingObjectReader
with default settings.reader
(Base64Variant defaultBase64) Factory method for constructingObjectReader
that will use specified Base64 encoding variant for Base64-encoded binary data.reader
(FormatSchema schema) Factory method for constructingObjectReader
that will pass specific schema object toJsonParser
used for reading content.reader
(ContextAttributes attrs) Factory method for constructingObjectReader
that will use specified default attributes.reader
(DeserializationFeature feature) Factory method for constructingObjectReader
with specified feature enabled (compared to settings that this mapper instance has).reader
(DeserializationFeature first, DeserializationFeature... other) Factory method for constructingObjectReader
with specified features enabled (compared to settings that this mapper instance has).reader
(InjectableValues injectableValues) Factory method for constructingObjectReader
that will use specified injectable values.reader
(JsonNodeFactory nodeFactory) Factory method for constructingObjectReader
that will use specifiedJsonNodeFactory
for constructing JSON trees.Factory method for constructingObjectReader
that will read or update instances of specified typereaderFor
(TypeReference<?> typeRef) Factory method for constructingObjectReader
that will read or update instances of specified typeFactory method for constructingObjectReader
that will read or update instances of specified typereaderForArrayOf
(Class<?> type) Factory method for constructingObjectReader
that will read values of a typeList<type>
.readerForListOf
(Class<?> type) Factory method for constructingObjectReader
that will read or update instances of a typeList<type>
.readerForMapOf
(Class<?> type) Factory method for constructingObjectReader
that will read or update instances of a typeMap<String, type>
Functionally same as:readerForUpdating
(Object valueToUpdate) Factory method for constructingObjectReader
that will update given Object (usually Bean, but can be a Collection or Map as well, but NOT an array) with JSON data.readerWithView
(Class<?> view) Factory method for constructingObjectReader
that will deserialize objects using specified JSON View (filter).protected Object
readTree
(byte[] content) Same asreadTree(InputStream)
except content read from passed-in byte array.readTree
(byte[] content, int offset, int len) Same asreadTree(InputStream)
except content read from passed-in byte array.Same asreadTree(InputStream)
except content read from passed-inFile
.readTree
(InputStream in) Method to deserialize JSON content as tree expressed using set ofJsonNode
instances.Same asreadTree(InputStream)
except content accessed through passed-inReader
Same asreadTree(InputStream)
except content read from passed-inString
Same asreadTree(InputStream)
except content read from passed-inURL
.Same asreadTree(InputStream)
except content read from passed-inPath
.Method to deserialize JSON content as a treeJsonNode
.<T> T
<T> T
readValue
(byte[] content, int offset, int len, TypeReference<T> valueTypeRef) <T> T
<T> T
<T> T
readValue
(byte[] content, TypeReference<T> valueTypeRef) <T> T
<T> T
<T> T
readValue
(DataInput src, TypeReference<T> valueTypeRef) <T> T
<T> T
Method to deserialize JSON content from given file into given Java type.<T> T
readValue
(File src, TypeReference<T> valueTypeRef) Method to deserialize JSON content from given file into given Java type.<T> T
Method to deserialize JSON content from given file into given Java type.<T> T
readValue
(InputStream src, Class<T> valueType) <T> T
readValue
(InputStream src, TypeReference<T> valueTypeRef) <T> T
readValue
(InputStream src, JavaType valueType) <T> T
<T> T
readValue
(Reader src, TypeReference<T> valueTypeRef) <T> T
<T> T
Method to deserialize JSON content from given JSON content String.<T> T
readValue
(String content, TypeReference<T> valueTypeRef) Method to deserialize JSON content from given JSON content String.<T> T
Method to deserialize JSON content from given JSON content String.<T> T
Method to deserialize JSON content from given resource into given Java type.<T> T
readValue
(URL src, TypeReference<T> valueTypeRef) Same asreadValue(java.net.URL, Class)
except that target specified byTypeReference
.<T> T
Same asreadValue(java.net.URL, Class)
except that target specified byJavaType
.<T> T
Method to deserialize JSON content from given path into given Java type.<T> T
readValue
(Path src, TypeReference<T> valueTypeRef) Method to deserialize JSON content from given path into given Java type.<T> T
Method to deserialize JSON content from given path into given Java type.<T> T
readValue
(JsonParser p, Class<T> valueType) 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 (likeBoolean
).final <T> T
readValue
(JsonParser p, ResolvedType valueType) Method to deserialize JSON content into a Java type, reference to which is passed as argument.<T> T
readValue
(JsonParser p, TypeReference<T> valueTypeRef) Method to deserialize JSON content into a Java type, reference to which is passed as argument.<T> T
readValue
(JsonParser p, JavaType valueType) Type-safe overloaded method, basically alias forreadValue(JsonParser, Class)
.<T> MappingIterator<T>
readValues
(JsonParser p, Class<T> valueType) Convenience method, equivalent in function to:<T> MappingIterator<T>
readValues
(JsonParser p, TypeReference<T> valueType) <T> MappingIterator<T>
readValues
(JsonParser p, JavaType valueType) Convenience method, equivalent in function to:<M extends ObjectMapper,
B extends MapperBuilder<M, B>>
MapperBuilder<M,B> rebuild()
Method for creating a newMapperBuilder
for constructing differently configuredObjectMapper
instance, starting with current configuration including base settings and registered modules.Accessor for internal configuration object that contains settings for serialization operations (writeValue(...)
methods)
NOTE: Not to be used by application code; needed by some testsstringNode
(String text) Method that can be used to get hold ofTokenStreamFactory
that this mapper uses if it needs to constructJsonParser
s and/orJsonGenerator
s.Method for constructing aJsonParser
out of JSON tree representation.<T> T
treeToValue
(TreeNode n, Class<T> valueType) Convenience conversion method that will bind data given JSON tree contains into specific value (usually bean) type.<T> T
treeToValue
(TreeNode n, TypeReference<T> toValueTypeRef) Same astreeToValue(TreeNode, JavaType)
but target type specified using fully resolvedTypeReference
.<T> T
treeToValue
(TreeNode n, JavaType valueType) Same astreeToValue(TreeNode, Class)
but target type specified using fully resolvedJavaType
.<T> T
updateValue
(T valueToUpdate, Object overrides) Convenience method similar toconvertValue(Object, JavaType)
but one in which<T extends JsonNode>
TvalueToTree
(Object fromValue) Method that is reverse oftreeToValue(tools.jackson.core.TreeNode, java.lang.Class<T>)
: it will convert given Java value (usually bean) into its equivalent Tree modelJsonNode
representation.version()
Method that will return version information stored in and read from jar that contains this class.writer()
Convenience method for constructingObjectWriter
with default settings.writer
(DateFormat df) Factory method for constructingObjectWriter
that will serialize objects using specifiedDateFormat
; or, if null passed, using timestamp (64-bit number.writer
(Base64Variant defaultBase64) Factory method for constructingObjectWriter
that will use specified Base64 encoding variant for Base64-encoded binary data.writer
(FormatSchema schema) Factory method for constructingObjectWriter
that will pass specific schema object toJsonGenerator
used for writing content.writer
(CharacterEscapes escapes) Factory method for constructingObjectReader
that will use specified character escaping details for output.writer
(ContextAttributes attrs) Factory method for constructingObjectWriter
that will use specified default attributes.writer
(FilterProvider filterProvider) Factory method for constructingObjectWriter
that will serialize objects using specified filter provider.writer
(SerializationFeature feature) Factory method for constructingObjectWriter
with specified feature enabled (compared to settings that this mapper instance has).writer
(SerializationFeature first, SerializationFeature... other) Factory method for constructingObjectWriter
with specified features enabled (compared to settings that this mapper instance has).protected Object
Factory method for constructingObjectWriter
that will serialize objects using specified root type, instead of actual runtime type of value.writerFor
(TypeReference<?> rootType) Factory method for constructingObjectWriter
that will serialize objects using specified root type, instead of actual runtime type of value.Factory method for constructingObjectWriter
that will serialize objects using specified root type, instead of actual runtime type of value.Factory method for constructingObjectWriter
that will serialize objects using the default pretty printer for indentationwriterWithView
(Class<?> serializationView) Factory method for constructingObjectWriter
that will serialize objects using specified JSON View (filter).void
writeTree
(JsonGenerator g, TreeNode rootNode) void
writeValue
(DataOutput out, Object value) void
writeValue
(File file, Object value) Method that can be used to serialize any Java value as JSON output, written to File provided.void
writeValue
(OutputStream out, Object value) Method that can be used to serialize any Java value as JSON output, using output stream provided (using encodingJsonEncoding.UTF8
).void
writeValue
(Writer w, Object value) Method that can be used to serialize any Java value as JSON output, using Writer provided.void
writeValue
(Path path, Object value) Method that can be used to serialize any Java value as JSON output, written to Path provided.void
writeValue
(JsonGenerator g, Object value) Method that can be used to serialize any Java value as JSON output, using providedJsonGenerator
.byte[]
writeValueAsBytes
(Object value) Method that can be used to serialize any Java value as a byte array.writeValueAsString
(Object value) Method that can be used to serialize any Java value as a String.
-
Field Details
-
_streamFactory
Factory used to createJsonParser
andJsonGenerator
instances as necessary. -
_typeFactory
Specific factory used for creatingJavaType
instances; needed to allow modules to add more custom type handling (mostly to support types of non-Java JVM languages) -
_injectableValues
Provider for values to inject in deserialized POJOs. -
_serializationContexts
Factory used for constructing per-callSerializationContext
s.Note: while serializers are only exposed
SerializationContext
, mappers and readers need to access additional API defined bySerializationContextExt
-
_serializationConfig
Configuration object that defines basic global settings for the serialization process -
_deserializationContexts
Factory used for constructing per-callDeserializationContext
s. -
_deserializationConfig
Configuration object that defines basic global settings for the serialization process -
_rootDeserializers
We will use a separate main-level Map for keeping track of root-level deserializers. This is where most successful cache lookups get resolved. Map will contain resolvers for all kinds of types, including container types: this is different from the component cache which will only cache bean deserializers.Given that we don't expect much concurrency for additions (should very quickly converge to zero after startup), let's explicitly define a low concurrency setting.
These may are either "raw" deserializers (when no type information is needed for base type), or type-wrapped deserializers (if it is needed)
-
_savedBuilderState
Minimal state retained to allow both re-building (by creating new builder) and JDK serialization of this mapper.- Since:
- 3.0
-
-
Constructor Details
-
ObjectMapper
public ObjectMapper()Default constructor, which will construct the default JSON-handlingTokenStreamFactory
as necessary and all other unmodified default settings, and no additional registered modules. -
ObjectMapper
Constructs instance that uses specifiedTokenStreamFactory
for constructing necessaryJsonParser
s and/orJsonGenerator
s, but without registering additional modules. -
ObjectMapper
Constructor usually called either byMapperBuilder.build()
or by sub-class constructor: will get all the settings through passed-in builder, including registration of any modules added to builder.
-
-
Method Details
-
rebuild
Method for creating a newMapperBuilder
for constructing differently configuredObjectMapper
instance, starting with current configuration including base settings and registered modules.- Since:
- 3.0
-
writeReplace
-
readResolve
-
version
Method that will return version information stored in and read from jar that contains this class. -
serializationConfig
Accessor for internal configuration object that contains settings for serialization operations (writeValue(...)
methods)
NOTE: Not to be used by application code; needed by some tests -
deserializationConfig
Accessor for internal configuration object that contains settings for deserialization operations (readValue(...)
methods)
NOTE: Not to be used by application code; needed by some tests -
tokenStreamFactory
Method that can be used to get hold ofTokenStreamFactory
that this mapper uses if it needs to constructJsonParser
s and/orJsonGenerator
s.WARNING: note that all
ObjectReader
andObjectWriter
instances created by this mapper usually share the same configuredTokenStreamFactory
, so changes to its configuration will "leak". To avoid such observed changes you should always use "with()" and "without()" method ofObjectReader
andObjectWriter
for changingStreamReadFeature
andStreamWriteFeature
settings to use on per-call basis.- Returns:
TokenStreamFactory
that this mapper uses when it needs to construct Json parser and generators- Since:
- 3.0
-
getNodeFactory
Method that can be used to get hold ofJsonNodeFactory
that this mapper will use when directly constructing rootJsonNode
instances for Trees.Note: this is just a shortcut for calling
getDeserializationConfig().getNodeFactory()
-
getInjectableValues
-
getTypeFactory
Accessor for getting currently configuredTypeFactory
instance. -
constructType
Convenience method for constructingJavaType
out of given type (typicallyjava.lang.Class
), but without explicit context. -
constructType
Convenience method for constructingJavaType
out of given type reference. -
isEnabled
-
isEnabled
-
isEnabled
-
isEnabled
Method for checking whether givenMapperFeature
is enabled. -
isEnabled
Method for checking whether given deserialization-specific feature is enabled. -
isEnabled
Method for checking whether given serialization-specific feature is enabled. -
getRegisteredModules
Method that may be used to find outJacksonModule
s that were registered when creating this mapper (if any).- Since:
- 3.0
-
createParser
Factory method for constructingJsonParser
that is properly wired to allow callbacks for deserialization: basically constructs aObjectReadContext
and then callsTokenStreamFactory.createParser(ObjectReadContext,java.io.File)
.- Throws:
JacksonException
- Since:
- 3.0
-
createParser
Factory method for constructingJsonParser
that is properly wired to allow callbacks for deserialization: basically constructs aObjectReadContext
and then callsTokenStreamFactory.createParser(ObjectReadContext,Path)
.- Throws:
JacksonException
- Since:
- 3.0
-
createParser
Factory method for constructingJsonParser
that is properly wired to allow callbacks for deserialization: basically constructs aObjectReadContext
and then callsTokenStreamFactory.createParser(ObjectReadContext,java.net.URL)
.- Throws:
JacksonException
- Since:
- 3.0
-
createParser
Factory method for constructingJsonParser
that is properly wired to allow callbacks for deserialization: basically constructs aObjectReadContext
and then callsTokenStreamFactory.createParser(ObjectReadContext,InputStream)
.- Throws:
JacksonException
- Since:
- 3.0
-
createParser
Factory method for constructingJsonParser
that is properly wired to allow callbacks for deserialization: basically constructs aObjectReadContext
and then callsTokenStreamFactory.createParser(ObjectReadContext,Reader)
.- Throws:
JacksonException
- Since:
- 3.0
-
createParser
Factory method for constructingJsonParser
that is properly wired to allow callbacks for deserialization: basically constructs aObjectReadContext
and then callsTokenStreamFactory.createParser(ObjectReadContext,byte[])
.- Throws:
JacksonException
- Since:
- 3.0
-
createParser
Factory method for constructingJsonParser
that is properly wired to allow callbacks for deserialization: basically constructs aObjectReadContext
and then callsTokenStreamFactory.createParser(ObjectReadContext,byte[],int,int)
.- Throws:
JacksonException
- Since:
- 3.0
-
createParser
Factory method for constructingJsonParser
that is properly wired to allow callbacks for deserialization: basically constructs aObjectReadContext
and then callsTokenStreamFactory.createParser(ObjectReadContext,String)
.- Throws:
JacksonException
- Since:
- 3.0
-
createParser
Factory method for constructingJsonParser
that is properly wired to allow callbacks for deserialization: basically constructs aObjectReadContext
and then callsTokenStreamFactory.createParser(ObjectReadContext,char[])
.- Throws:
JacksonException
- Since:
- 3.0
-
createParser
Factory method for constructingJsonParser
that is properly wired to allow callbacks for deserialization: basically constructs aObjectReadContext
and then callsTokenStreamFactory.createParser(ObjectReadContext,char[],int,int)
.- Throws:
JacksonException
- Since:
- 3.0
-
createParser
Factory method for constructingJsonParser
that is properly wired to allow callbacks for deserialization: basically constructs aObjectReadContext
and then callsTokenStreamFactory.createParser(ObjectReadContext,DataInput)
.- Throws:
JacksonException
- Since:
- 3.0
-
createNonBlockingByteArrayParser
Factory method for constructing non-blockingJsonParser
that is properly wired to allow configuration access (and, if relevant for parser, callbacks): essentially constructs aObjectReadContext
and then callsTokenStreamFactory.createParser(ObjectReadContext,DataInput)
.- Throws:
JacksonException
- Since:
- 3.0
-
createGenerator
Factory method for constructingJsonGenerator
that is properly wired to allow callbacks for serialization: basically constructs aObjectWriteContext
and then callsTokenStreamFactory.createGenerator(ObjectWriteContext,OutputStream)
.- Throws:
JacksonException
- Since:
- 3.0
-
createGenerator
Factory method for constructingJsonGenerator
that is properly wired to allow callbacks for serialization: basically constructs aObjectWriteContext
and then callsTokenStreamFactory.createGenerator(ObjectWriteContext,OutputStream,JsonEncoding)
.- Throws:
JacksonException
- Since:
- 3.0
-
createGenerator
Factory method for constructingJsonGenerator
that is properly wired to allow callbacks for serialization: basically constructs aObjectWriteContext
and then callsTokenStreamFactory.createGenerator(ObjectWriteContext,Writer)
.- Throws:
JacksonException
- Since:
- 3.0
-
createGenerator
Factory method for constructingJsonGenerator
that is properly wired to allow callbacks for serialization: basically constructs aObjectWriteContext
and then callsTokenStreamFactory.createGenerator(ObjectWriteContext,File,JsonEncoding)
.- Throws:
JacksonException
- Since:
- 3.0
-
createGenerator
Factory method for constructingJsonGenerator
that is properly wired to allow callbacks for serialization: basically constructs aObjectWriteContext
and then callsTokenStreamFactory.createGenerator(ObjectWriteContext,Path,JsonEncoding)
.- Throws:
JacksonException
- Since:
- 3.0
-
createGenerator
Factory method for constructingJsonGenerator
that is properly wired to allow callbacks for serialization: basically constructs aObjectWriteContext
and then callsTokenStreamFactory.createGenerator(ObjectWriteContext,DataOutput)
.- Throws:
JacksonException
- Since:
- 3.0
-
createObjectNode
Note: return type is co-variant, as basic
TreeCodec
abstraction cannot refer to concrete node types (as it's part of core package, whereas impls are part of mapper package)- Specified by:
createObjectNode
in interfaceTreeCodec
-
createArrayNode
Note: return type is co-variant, as basic
TreeCodec
abstraction cannot refer to concrete node types (as it's part of core package, whereas impls are part of mapper package)- Specified by:
createArrayNode
in interfaceTreeCodec
-
booleanNode
- Specified by:
booleanNode
in interfaceTreeCodec
-
stringNode
- Specified by:
stringNode
in interfaceTreeCodec
-
missingNode
- Specified by:
missingNode
in interfaceTreeCodec
-
nullNode
-
treeAsTokens
Method for constructing aJsonParser
out of JSON tree representation.- Specified by:
treeAsTokens
in interfaceTreeCodec
- Parameters:
n
- Root node of the tree that resulting parser will read from
-
readTree
Method to deserialize JSON content as a treeJsonNode
. ReturnsJsonNode
that represents the root of the resulting tree, if there was content to read, ornull
if no more content is accessible via passedJsonParser
.NOTE! Behavior with end-of-input (no more content) differs between this
readTree
method, and all other methods that take input source: latter will return "missing node", NOTnull
- Specified by:
readTree
in interfaceTreeCodec
- Returns:
- a
JsonNode
, if valid JSON content found; null if input has no content to bind -- note, however, that if JSONnull
token is found, it will be represented as a non-nullJsonNode
(one that returnstrue
forJsonNode.isNull()
- Throws:
JacksonIOException
- if a low-level I/O problem (unexpected end-of-input, network error) occurs (passed through as-is without additional wrapping -- note that this is one case whereDeserializationFeature.WRAP_EXCEPTIONS
does NOT result in wrapping of exception even if enabled)StreamReadException
- if underlying input contains invalid content of typeJsonParser
supports (JSON for default case)JacksonException
-
writeTree
- Specified by:
writeTree
in interfaceTreeCodec
- Throws:
JacksonException
-
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 (likeBoolean
).Note: this method should NOT be used if the result type is a container (
Collection
orMap
. The reason is that due to type erasure, key and value types cannot be introspected when using this method.- Throws:
JacksonIOException
- if a low-level I/O problem (unexpected end-of-input, network error) occurs (passed through as-is without additional wrapping -- note that this is one case whereDeserializationFeature.WRAP_EXCEPTIONS
does NOT result in wrapping of exception even if enabled)StreamReadException
- if underlying input contains invalid content of typeJsonParser
supports (JSON for default case)DatabindException
- if the input JSON structure does not match structure expected for result type (or has other mismatch issues)JacksonException
-
readValue
Method to deserialize JSON content into a Java type, reference to which is passed as argument. Type is passed using so-called "super type token" (see ) and specifically needs to be used if the root type is a parameterized (generic) container type.- Throws:
JacksonIOException
- if a low-level I/O problem (unexpected end-of-input, network error) occurs (passed through as-is without additional wrapping -- note that this is one case whereDeserializationFeature.WRAP_EXCEPTIONS
does NOT result in wrapping of exception even if enabled)StreamReadException
- if underlying input contains invalid content of typeJsonParser
supports (JSON for default case)DatabindException
- if the input JSON structure does not match structure expected for result type (or has other mismatch issues)JacksonException
-
readValue
Method to deserialize JSON content into a Java type, reference to which is passed as argument. Type is passed using Jackson specific type; instance of which can be constructed usingTypeFactory
.- Throws:
JacksonIOException
- if a low-level I/O problem (unexpected end-of-input, network error) occurs (passed through as-is without additional wrapping -- note that this is one case whereDeserializationFeature.WRAP_EXCEPTIONS
does NOT result in wrapping of exception even if enabled)StreamReadException
- if underlying input contains invalid content of typeJsonParser
supports (JSON for default case)DatabindException
- if the input JSON structure does not match structure expected for result type (or has other mismatch issues)JacksonException
-
readValue
Type-safe overloaded method, basically alias forreadValue(JsonParser, Class)
.- Throws:
JacksonIOException
- if a low-level I/O problem (unexpected end-of-input, network error) occurs (passed through as-is without additional wrapping -- note that this is one case whereDeserializationFeature.WRAP_EXCEPTIONS
does NOT result in wrapping of exception even if enabled)StreamReadException
- if underlying input contains invalid content of typeJsonParser
supports (JSON for default case)DatabindException
- if the input JSON structure does not match structure expected for result type (or has other mismatch issues)JacksonException
-
readValues
Convenience method, equivalent in function to:readerFor(valueType).readValues(p);
Method for reading sequence of Objects from parser stream. Sequence can be either root-level "unwrapped" sequence (without surrounding JSON array), or a sequence contained in a JSON Array. In either case
JsonParser
MUST point to the first token of the first element, OR not point to any token (in which case it is advanced to the next token). This means, specifically, that for wrapped sequences, parser MUST NOT point to the surroundingSTART_ARRAY
(one that contains values to read) but rather to the token following it which is the first token of the first value to read.Note that
ObjectReader
has more complete set of variants.- Throws:
JacksonException
-
readValues
Convenience method, equivalent in function to:readerFor(valueType).readValues(p);
Type-safe overload of
readValues(JsonParser, JavaType)
.- Throws:
JacksonException
-
readValues
public <T> MappingIterator<T> readValues(JsonParser p, TypeReference<T> valueType) throws JacksonException - Throws:
JacksonException
-
readTree
Method to deserialize JSON content as tree expressed using set ofJsonNode
instances. Returns root of the resulting tree (where root can consist of just a single node if the current event is a value event, not container).If a low-level I/O problem (missing input, network error) occurs, a
IOException
will be thrown. If a parsing problem occurs (invalid JSON),StreamReadException
will be thrown. If no content is found from input (end-of-input), Javanull
will be returned.- Parameters:
in
- Input stream used to read JSON content for building the JSON tree.- Returns:
- a
JsonNode
, if valid JSON content found; null if input has no content to bind -- note, however, that if JSONnull
token is found, it will be represented as a non-nullJsonNode
(one that returnstrue
forJsonNode.isNull()
- Throws:
StreamReadException
- if underlying input contains invalid content of typeJsonParser
supports (JSON for default case)JacksonException
-
readTree
Same asreadTree(InputStream)
except content accessed through passed-inReader
- Throws:
JacksonException
-
readTree
Same asreadTree(InputStream)
except content read from passed-inString
- Throws:
JacksonException
-
readTree
Same asreadTree(InputStream)
except content read from passed-in byte array.- Throws:
JacksonException
-
readTree
Same asreadTree(InputStream)
except content read from passed-in byte array.- Throws:
JacksonException
-
readTree
Same asreadTree(InputStream)
except content read from passed-inFile
.- Throws:
JacksonException
-
readTree
Same asreadTree(InputStream)
except content read from passed-inPath
.- Throws:
JacksonException
- Since:
- 3.0
-
readTree
Same asreadTree(InputStream)
except content read from passed-inURL
.NOTE: handling of
URL
is delegated toTokenStreamFactory.createParser(ObjectReadContext, java.net.URL)
s and usually simply callsURL.openStream()
, meaning no special handling is done. If different HTTP connection options are needed you will need to createInputStream
separately.- Throws:
JacksonException
-
writeValue
Method that can be used to serialize any Java value as JSON output, using providedJsonGenerator
.- Throws:
JacksonException
-
treeToValue
Convenience conversion method that will bind data given JSON tree contains into specific value (usually bean) type.Functionally equivalent to:
objectMapper.convertValue(n, valueClass);
- Throws:
JacksonException
-
treeToValue
Same astreeToValue(TreeNode, Class)
but target type specified using fully resolvedJavaType
.- Throws:
JacksonException
-
treeToValue
Same astreeToValue(TreeNode, JavaType)
but target type specified using fully resolvedTypeReference
.- Throws:
JacksonException
-
valueToTree
Method that is reverse oftreeToValue(tools.jackson.core.TreeNode, java.lang.Class<T>)
: it will convert given Java value (usually bean) into its equivalent Tree modelJsonNode
representation. Functionally similar to serializing value into token stream and parsing that stream back as tree model node, but more efficient asTokenBuffer
is used to contain the intermediate representation instead of fully serialized contents.NOTE: while results are usually identical to that of serialization followed by deserialization, this is not always the case. In some cases serialization into intermediate representation will retain encapsulation of things like raw value (
RawValue
) or basic node identity (JsonNode
). If so, result is a valid tree, but values are not re-constructed through actual format representation. So if transformation requires actual materialization of encoded content, it will be necessary to do actual serialization.- Type Parameters:
T
- Actual node type; usually either basicJsonNode
orObjectNode
- Parameters:
fromValue
- Java value to convert- Returns:
- (non-null) Root node of the resulting content tree: in case of
null
value node for whichJsonNode.isNull()
returnstrue
. - Throws:
JacksonException
-
readValue
Method to deserialize JSON content from given file into given Java type.- Throws:
JacksonIOException
- if a low-level I/O problem (unexpected end-of-input, network error) occurs (passed through as-is without additional wrapping -- note that this is one case whereDeserializationFeature.WRAP_EXCEPTIONS
does NOT result in wrapping of exception even if enabled)StreamReadException
- if underlying input contains invalid content of typeJsonParser
supports (JSON for default case)DatabindException
- if the input JSON structure does not match structure expected for result type (or has other mismatch issues)JacksonException
-
readValue
Method to deserialize JSON content from given file into given Java type.- Throws:
JacksonIOException
- if a low-level I/O problem (unexpected end-of-input, network error) occurs (passed through as-is without additional wrapping -- note that this is one case whereDeserializationFeature.WRAP_EXCEPTIONS
does NOT result in wrapping of exception even if enabled)StreamReadException
- if underlying input contains invalid content of typeJsonParser
supports (JSON for default case)DatabindException
- if the input JSON structure does not match structure expected for result type (or has other mismatch issues)JacksonException
-
readValue
Method to deserialize JSON content from given file into given Java type.- Throws:
JacksonIOException
- if a low-level I/O problem (unexpected end-of-input, network error) occurs (passed through as-is without additional wrapping -- note that this is one case whereDeserializationFeature.WRAP_EXCEPTIONS
does NOT result in wrapping of exception even if enabled)StreamReadException
- if underlying input contains invalid content of typeJsonParser
supports (JSON for default case)DatabindException
- if the input JSON structure does not match structure expected for result type (or has other mismatch issues)JacksonException
-
readValue
Method to deserialize JSON content from given path into given Java type.- Throws:
JacksonIOException
- if a low-level I/O problem (unexpected end-of-input, network error) occurs (passed through as-is without additional wrapping -- note that this is one case whereDeserializationFeature.WRAP_EXCEPTIONS
does NOT result in wrapping of exception even if enabled)StreamReadException
- if underlying input contains invalid content of typeJsonParser
supports (JSON for default case)DatabindException
- if the input JSON structure does not match structure expected for result type (or has other mismatch issues)JacksonException
- Since:
- 3.0
-
readValue
Method to deserialize JSON content from given path into given Java type.- Throws:
JacksonIOException
- if a low-level I/O problem (unexpected end-of-input, network error) occurs (passed through as-is without additional wrapping -- note that this is one case whereDeserializationFeature.WRAP_EXCEPTIONS
does NOT result in wrapping of exception even if enabled)StreamReadException
- if underlying input contains invalid content of typeJsonParser
supports (JSON for default case)DatabindException
- if the input JSON structure does not match structure expected for result type (or has other mismatch issues)JacksonException
- Since:
- 3.0
-
readValue
Method to deserialize JSON content from given path into given Java type.- Throws:
JacksonIOException
- if a low-level I/O problem (unexpected end-of-input, network error) occurs (passed through as-is without additional wrapping -- note that this is one case whereDeserializationFeature.WRAP_EXCEPTIONS
does NOT result in wrapping of exception even if enabled)StreamReadException
- if underlying input contains invalid content of typeJsonParser
supports (JSON for default case)DatabindException
- if the input JSON structure does not match structure expected for result type (or has other mismatch issues)JacksonException
- Since:
- 3.0
-
readValue
Method to deserialize JSON content from given resource into given Java type.NOTE: handling of
URL
is delegated toTokenStreamFactory.createParser(ObjectReadContext, java.net.URL)
and usually simply callsURL.openStream()
, meaning no special handling is done. If different HTTP connection options are needed you will need to createInputStream
separately.- Throws:
JacksonIOException
- if a low-level I/O problem (unexpected end-of-input, network error) occurs (passed through as-is without additional wrapping -- note that this is one case whereDeserializationFeature.WRAP_EXCEPTIONS
does NOT result in wrapping of exception even if enabled)StreamReadException
- if underlying input contains invalid content of typeJsonParser
supports (JSON for default case)DatabindException
- if the input JSON structure does not match structure expected for result type (or has other mismatch issues)JacksonException
-
readValue
Same asreadValue(java.net.URL, Class)
except that target specified byTypeReference
.- Throws:
JacksonException
-
readValue
Same asreadValue(java.net.URL, Class)
except that target specified byJavaType
.- Throws:
JacksonException
-
readValue
Method to deserialize JSON content from given JSON content String.- Throws:
JacksonIOException
- if a low-level I/O problem (unexpected end-of-input, network error) occurs (passed through as-is without additional wrapping -- note that this is one case whereDeserializationFeature.WRAP_EXCEPTIONS
does NOT result in wrapping of exception even if enabled)StreamReadException
- if underlying input contains invalid content of typeJsonParser
supports (JSON for default case)DatabindException
- if the input JSON structure does not match structure expected for result type (or has other mismatch issues)JacksonException
-
readValue
Method to deserialize JSON content from given JSON content String.- Throws:
JacksonIOException
- if a low-level I/O problem (unexpected end-of-input, network error) occurs (passed through as-is without additional wrapping -- note that this is one case whereDeserializationFeature.WRAP_EXCEPTIONS
does NOT result in wrapping of exception even if enabled)StreamReadException
- if underlying input contains invalid content of typeJsonParser
supports (JSON for default case)DatabindException
- if the input JSON structure does not match structure expected for result type (or has other mismatch issues)JacksonException
-
readValue
Method to deserialize JSON content from given JSON content String.- Throws:
JacksonIOException
- if a low-level I/O problem (unexpected end-of-input, network error) occurs (passed through as-is without additional wrapping -- note that this is one case whereDeserializationFeature.WRAP_EXCEPTIONS
does NOT result in wrapping of exception even if enabled)StreamReadException
- if underlying input contains invalid content of typeJsonParser
supports (JSON for default case)DatabindException
- if the input JSON structure does not match structure expected for result type (or has other mismatch issues)JacksonException
-
readValue
- Throws:
JacksonException
-
readValue
- Throws:
JacksonException
-
readValue
- Throws:
JacksonException
-
readValue
- Throws:
JacksonException
-
readValue
- Throws:
JacksonException
-
readValue
- Throws:
JacksonException
-
readValue
- Throws:
JacksonException
-
readValue
public <T> T readValue(byte[] content, int offset, int len, Class<T> valueType) throws JacksonException - Throws:
JacksonException
-
readValue
- Throws:
JacksonException
-
readValue
public <T> T readValue(byte[] content, int offset, int len, TypeReference<T> valueTypeRef) throws JacksonException - Throws:
JacksonException
-
readValue
- Throws:
JacksonException
-
readValue
public <T> T readValue(byte[] content, int offset, int len, JavaType valueType) throws JacksonException - Throws:
JacksonException
-
readValue
- Throws:
JacksonException
-
readValue
- Throws:
JacksonException
-
readValue
- Throws:
JacksonException
-
writeValue
Method that can be used to serialize any Java value as JSON output, written to File provided.- Throws:
JacksonException
-
writeValue
Method that can be used to serialize any Java value as JSON output, written to Path provided.- Throws:
JacksonException
- Since:
- 3.0
-
writeValue
Method that can be used to serialize any Java value as JSON output, using output stream provided (using encodingJsonEncoding.UTF8
).Note: method does not close the underlying stream explicitly here; however,
TokenStreamFactory
this mapper uses may choose to close the stream depending on its settings (by default, it will try to close it whenJsonGenerator
we construct is closed).- Throws:
JacksonException
-
writeValue
- Throws:
JacksonException
-
writeValue
Method that can be used to serialize any Java value as JSON output, using Writer provided.Note: method does not close the underlying stream explicitly here; however,
TokenStreamFactory
this mapper uses may choose to close the stream depending on its settings (by default, it will try to close it whenJsonGenerator
we construct is closed).- Throws:
JacksonException
-
writeValueAsString
Method that can be used to serialize any Java value as a String. Functionally equivalent to callingwriteValue(Writer,Object)
withStringWriter
and constructing String, but more efficient.- Throws:
JacksonException
-
writeValueAsBytes
Method that can be used to serialize any Java value as a byte array. Functionally equivalent to callingwriteValue(Writer,Object)
withByteArrayOutputStream
and getting bytes, but more efficient. Encoding used will be UTF-8.- Throws:
JacksonException
-
_configAndWriteValue
protected final void _configAndWriteValue(SerializationContextExt prov, JsonGenerator g, Object value) throws JacksonException Method called to configure the generator as necessary and then call write functionality- Throws:
JacksonException
-
_writeCloseableValue
protected final void _writeCloseableValue(JsonGenerator g, Object value, SerializationConfig cfg) throws JacksonException Helper method used when value to serialize isCloseable
and itsclose()
method is to be called right after serialization has been called- Throws:
JacksonException
-
writer
Convenience method for constructingObjectWriter
with default settings. -
writer
Factory method for constructingObjectWriter
with specified feature enabled (compared to settings that this mapper instance has). -
writer
Factory method for constructingObjectWriter
with specified features enabled (compared to settings that this mapper instance has). -
writer
Factory method for constructingObjectWriter
that will serialize objects using specifiedDateFormat
; or, if null passed, using timestamp (64-bit number. -
writerWithView
Factory method for constructingObjectWriter
that will serialize objects using specified JSON View (filter). -
writerFor
Factory method for constructingObjectWriter
that will serialize objects using specified root type, instead of actual runtime type of value. Type must be a super-type of runtime type.Main reason for using this method is performance, as writer is able to pre-fetch serializer to use before write, and if writer is used more than once this avoids addition per-value serializer lookups.
-
writerFor
Factory method for constructingObjectWriter
that will serialize objects using specified root type, instead of actual runtime type of value. Type must be a super-type of runtime type.Main reason for using this method is performance, as writer is able to pre-fetch serializer to use before write, and if writer is used more than once this avoids addition per-value serializer lookups.
-
writerFor
Factory method for constructingObjectWriter
that will serialize objects using specified root type, instead of actual runtime type of value. Type must be a super-type of runtime type.Main reason for using this method is performance, as writer is able to pre-fetch serializer to use before write, and if writer is used more than once this avoids addition per-value serializer lookups.
-
writerWithDefaultPrettyPrinter
Factory method for constructingObjectWriter
that will serialize objects using the default pretty printer for indentation -
writer
Factory method for constructingObjectWriter
that will serialize objects using specified filter provider. -
writer
Factory method for constructingObjectWriter
that will pass specific schema object toJsonGenerator
used for writing content.- Parameters:
schema
- Schema to pass to generator
-
writer
Factory method for constructingObjectWriter
that will use specified Base64 encoding variant for Base64-encoded binary data. -
writer
Factory method for constructingObjectReader
that will use specified character escaping details for output. -
writer
Factory method for constructingObjectWriter
that will use specified default attributes. -
reader
Factory method for constructingObjectReader
with default settings. Note that the resulting instance is NOT usable as is, without defining expected value type. -
reader
Factory method for constructingObjectReader
with specified feature enabled (compared to settings that this mapper instance has). Note that the resulting instance is NOT usable as is, without defining expected value type. -
reader
Factory method for constructingObjectReader
with specified features enabled (compared to settings that this mapper instance has). Note that the resulting instance is NOT usable as is, without defining expected value type. -
readerForUpdating
Factory method for constructingObjectReader
that will update given Object (usually Bean, but can be a Collection or Map as well, but NOT an array) with JSON data. Deserialization occurs normally except that the root-level value in JSON is not used for instantiating a new object; instead give updateable object is used as root. Runtime type of value object is used for locating deserializer, unless overridden by other factory methods ofObjectReader
-
readerFor
Factory method for constructingObjectReader
that will read or update instances of specified type -
readerFor
Factory method for constructingObjectReader
that will read or update instances of specified type -
readerFor
Factory method for constructingObjectReader
that will read or update instances of specified type -
readerForArrayOf
Factory method for constructingObjectReader
that will read values of a typeList<type>
. Functionally same as:readerFor(type[].class);
-
readerForListOf
Factory method for constructingObjectReader
that will read or update instances of a typeList<type>
. Functionally same as:readerFor(new TypeReference<List<type>>() { });
-
readerForMapOf
Factory method for constructingObjectReader
that will read or update instances of a typeMap<String, type>
Functionally same as:readerFor(new TypeReference<Map<String, type>>() { });
- Since:
- 2.11
-
reader
Factory method for constructingObjectReader
that will use specifiedJsonNodeFactory
for constructing JSON trees. -
reader
Factory method for constructingObjectReader
that will pass specific schema object toJsonParser
used for reading content.- Parameters:
schema
- Schema to pass to parser
-
reader
Factory method for constructingObjectReader
that will use specified injectable values.- Parameters:
injectableValues
- Injectable values to use
-
readerWithView
Factory method for constructingObjectReader
that will deserialize objects using specified JSON View (filter). -
reader
Factory method for constructingObjectReader
that will use specified Base64 encoding variant for Base64-encoded binary data. -
reader
Factory method for constructingObjectReader
that will use specified default attributes. -
convertValue
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.This method is functionally similar to first serializing given value into JSON, and then binding JSON data into value of given type, but should be more efficient since full serialization does not (need to) occur. However, same converters (serializers, deserializers) will be used as for data binding, meaning same object mapper configuration works.
Note that behavior changed slightly between Jackson 2.9 and 2.10 so that whereas earlier some optimizations were used to avoid write/read cycle in case input was of target type, from 2.10 onwards full processing is always performed. See databind#2220 for full details of the change.
Further note that it is possible that in some cases behavior does differ from full serialize-then-deserialize cycle: in most case differences are unintentional (that is, flaws to fix) and should be reported, but the behavior is not guaranteed to be 100% the same: the goal is to allow efficient value conversions for structurally compatible Objects, according to standard Jackson configuration.
Further note that this functionality is not designed to support "advanced" use cases, such as conversion of polymorphic values, or cases where Object Identity is used.
- Throws:
IllegalArgumentException
- If conversion fails due to incompatible type; if so, root cause will contain underlying checked exception data binding functionality threw
-
convertValue
public <T> T convertValue(Object fromValue, TypeReference<T> toValueTypeRef) throws IllegalArgumentException - Throws:
IllegalArgumentException
-
convertValue
- Throws:
IllegalArgumentException
-
_convert
Actual conversion implementation: instead of using existing read and write methods, much of code is inlined. Reason for this is that we must avoid root value wrapping/unwrapping both for efficiency and for correctness. If root value wrapping/unwrapping is actually desired, caller must use explicitwriteValue
andreadValue
methods.- Throws:
JacksonException
-
updateValue
Convenience method similar toconvertValue(Object, JavaType)
but one in whichImplementation is approximately as follows:
- Serialize `updateWithValue` into
TokenBuffer
- Construct
ObjectReader
with `valueToUpdate` (usingreaderForUpdating(Object)
) - Construct
JsonParser
(usingTokenBuffer.asParser(ObjectReadContext)
) - Update using
ObjectReader.readValue(JsonParser)
. - Return `valueToUpdate`
Note that update is "shallow" in that only first level of properties (or, immediate contents of container to update) are modified, unless properties themselves indicate that merging should be applied for contents. Such merging can be specified using annotations (see
JsonMerge
) as well as using "config overrides" (seeMapperBuilder.withConfigOverride(java.lang.Class<?>, java.util.function.Consumer<tools.jackson.databind.cfg.MutableConfigOverride>)
andMapperBuilder.defaultMergeable(java.lang.Boolean)
).- Parameters:
valueToUpdate
- Object to updateoverrides
- Object to conceptually serialize and merge into value to update; can be thought of as a provider for overrides to apply.- 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)
- Throws:
JacksonException
- if there are structural incompatibilities that prevent update.
- Serialize `updateWithValue` into
-
acceptJsonFormatVisitor
Method for visiting type hierarchy for given type, using specified visitor.This method can be used for things like generating JSON Schema instance for specified type.
- Parameters:
type
- Type to generate schema for (possibly with generic signature)
-
acceptJsonFormatVisitor
-
acceptJsonFormatVisitor
Method for visiting type hierarchy for given type, using specified visitor. Visitation usesSerializer
hierarchy and related propertiesThis method can be used for things like generating JSON Schema instance for specified type.
- Parameters:
type
- Type to generate schema for (possibly with generic signature)
-
clearCaches
public void clearCaches()Method that will clear all caches this mapper owns.This method should not be needed in normal operation, but may be useful to avoid class-loader memory leaks when reloading applications.
- Since:
- 2.19
-
_serializationContext
Overridable helper method used for constructingSerializationContext
to use for serialization. -
_serializationContext
-
_readValue
protected Object _readValue(DeserializationContextExt ctxt, JsonParser p, JavaType valueType) throws JacksonException Actual implementation of value reading+binding operation.- Throws:
JacksonException
-
_readMapAndClose
protected Object _readMapAndClose(DeserializationContextExt ctxt, JsonParser p0, JavaType valueType) throws JacksonException - Throws:
JacksonException
-
_readTreeAndClose
protected JsonNode _readTreeAndClose(DeserializationContextExt ctxt, JsonParser p0) throws JacksonException Similar to_readMapAndClose(tools.jackson.databind.deser.DeserializationContextExt, tools.jackson.core.JsonParser, tools.jackson.databind.JavaType)
but specialized forJsonNode
reading.- Throws:
JacksonException
-
_deserializationContext
Internal helper method called to create an instance ofDeserializationContext
for deserializing a single root value. Can be overridden if a custom context is needed. -
_deserializationContext
-
_deserializationContext
protected DeserializationContextExt _deserializationContext(DeserializationConfig config, JsonParser p) -
_initForReading
Method called to ensure that given parser is ready for reading content for data binding.- 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.
- Throws:
JacksonException
- if the initialization fails during initialization of the streaming parser
-
_verifyNoTrailingTokens
protected final void _verifyNoTrailingTokens(JsonParser p, DeserializationContext ctxt, JavaType bindType) throws JacksonException - Throws:
JacksonException
-
_newReader
Factory method sub-classes must override, to produceObjectReader
instances of proper sub-type -
_newReader
protected ObjectReader _newReader(DeserializationConfig config, JavaType valueType, Object valueToUpdate, FormatSchema schema, InjectableValues injectableValues) Factory method sub-classes must override, to produceObjectReader
instances of proper sub-type -
_newWriter
Factory method sub-classes must override, to produceObjectWriter
instances of proper sub-type -
_newWriter
Factory method sub-classes must override, to produceObjectWriter
instances of proper sub-type -
_newWriter
Factory method sub-classes must override, to produceObjectWriter
instances of proper sub-type -
_findRootDeserializer
protected ValueDeserializer<Object> _findRootDeserializer(DeserializationContext ctxt, JavaType valueType) throws JacksonException Method called to locate deserializer for the passed root-level value.- Throws:
JacksonException
-
_verifySchemaType
-
_assertNotNull
-