- 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 ObjectReaders and ObjectWriters 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 JacksonModules) is complete,
instance is created by calling MapperBuilder.build() method.
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 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 DeserializationConfigConfiguration object that defines basic global settings for the serialization processprotected final DeserializationContextsFactory used for constructing per-callDeserializationContextinstances.protected final InjectableValuesProvider 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 MapperBuilderStateMinimal state retained to allow both re-building (by creating new builder) and JDK serialization of this mapper.protected final SerializationConfigConfiguration object that defines basic global settings for the serialization processprotected final SerializationContextsFactory used for constructing per-callSerializationContextinstances.protected final TokenStreamFactoryFactory used to createJsonParserandJsonGeneratorinstances as necessary.protected final TypeFactorySpecific factory used for creatingJavaTypeinstances; 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-handlingTokenStreamFactoryas necessary and all other unmodified default settings, and no additional registered modules.ObjectMapper(TokenStreamFactory streamFactory) Constructs instance that uses specifiedTokenStreamFactoryfor constructing necessaryJsonParsers and/orJsonGenerators, but without registering additional modules.protectedObjectMapper(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 ObjectActual conversion implementation: instead of using existing read and write methods, much of code is inlined.protected DeserializationContextExtInternal helper method called to create an instance ofDeserializationContextfor deserializing a single root value.protected DeserializationContextExtprotected 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 produceObjectReaderinstances of proper sub-typeprotected ObjectReader_newReader(DeserializationConfig config, JavaType valueType, Object valueToUpdate, FormatSchema schema, InjectableValues injectableValues) Factory method sub-classes must override, to produceObjectReaderinstances of proper sub-typeprotected ObjectWriter_newWriter(SerializationConfig config) Factory method sub-classes must override, to produceObjectWriterinstances of proper sub-typeprotected ObjectWriter_newWriter(SerializationConfig config, FormatSchema schema) Factory method sub-classes must override, to produceObjectWriterinstances of proper sub-typeprotected ObjectWriter_newWriter(SerializationConfig config, JavaType rootType, PrettyPrinter pp) Factory method sub-classes must override, to produceObjectWriterinstances of proper sub-typeprotected Object_readMapAndClose(DeserializationContextExt ctxt, JsonParser p0, JavaType valueType) protected JsonNodeSimilar to_readMapAndClose(tools.jackson.databind.deser.DeserializationContextExt, tools.jackson.core.JsonParser, tools.jackson.databind.JavaType)but specialized forJsonNodereading.protected Object_readValue(DeserializationContextExt ctxt, JsonParser p, JavaType valueType) Actual implementation of value reading+binding operation.protected SerializationContextExtOverridable helper method used for constructingSerializationContextto 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 isCloseableand itsclose()method is to be called right after serialization has been calledvoidacceptJsonFormatVisitor(Class<?> type, JsonFormatVisitorWrapper visitor) Method for visiting type hierarchy for given type, using specified visitor.voidacceptJsonFormatVisitor(TypeReference<?> typeRef, JsonFormatVisitorWrapper visitor) voidacceptJsonFormatVisitor(JavaType type, JsonFormatVisitorWrapper visitor) Method for visiting type hierarchy for given type, using specified visitor.booleanNode(boolean b) voidMethod that will clear all caches this mapper owns.constructType(Type type) Convenience method for constructingJavaTypeout of given type (typicallyjava.lang.Class), but without explicit context.constructType(TypeReference<?> typeReference) Convenience method for constructingJavaTypeout of given type reference.<T> TconvertValue(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> TconvertValue(Object fromValue, TypeReference<T> toValueTypeRef) <T> TconvertValue(Object fromValue, JavaType toValueType) Note: return type is co-variant, as basicTreeCodecabstraction cannot refer to concrete node types (as it's part of core package, whereas impls are part of mapper package)Factory method for constructingJsonGeneratorthat is properly wired to allow callbacks for serialization: basically constructs aObjectWriteContextand then callsTokenStreamFactory.createGenerator(ObjectWriteContext,DataOutput).createGenerator(File f, JsonEncoding enc) Factory method for constructingJsonGeneratorthat is properly wired to allow callbacks for serialization: basically constructs aObjectWriteContextand then callsTokenStreamFactory.createGenerator(ObjectWriteContext,File,JsonEncoding).Factory method for constructingJsonGeneratorthat is properly wired to allow callbacks for serialization: basically constructs aObjectWriteContextand then callsTokenStreamFactory.createGenerator(ObjectWriteContext,OutputStream).createGenerator(OutputStream out, JsonEncoding enc) Factory method for constructingJsonGeneratorthat is properly wired to allow callbacks for serialization: basically constructs aObjectWriteContextand then callsTokenStreamFactory.createGenerator(ObjectWriteContext,OutputStream,JsonEncoding).Factory method for constructingJsonGeneratorthat is properly wired to allow callbacks for serialization: basically constructs aObjectWriteContextand then callsTokenStreamFactory.createGenerator(ObjectWriteContext,Writer).createGenerator(Path path, JsonEncoding enc) Factory method for constructingJsonGeneratorthat is properly wired to allow callbacks for serialization: basically constructs aObjectWriteContextand then callsTokenStreamFactory.createGenerator(ObjectWriteContext,Path,JsonEncoding).Factory method for constructing non-blockingJsonParserthat is properly wired to allow configuration access (and, if relevant for parser, callbacks): essentially constructs aObjectReadContextand then callsTokenStreamFactory.createNonBlockingByteArrayParser(ObjectReadContext).Factory method for constructing non-blockingJsonParserthat is properly wired to allow configuration access (and, if relevant for parser, callbacks): essentially constructs aObjectReadContextand then callsTokenStreamFactory.createNonBlockingByteBufferParser(ObjectReadContext).Note: return type is co-variant, as basicTreeCodecabstraction 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 constructingJsonParserthat is properly wired to allow callbacks for deserialization: basically constructs aObjectReadContextand then callsTokenStreamFactory.createParser(ObjectReadContext,byte[]).createParser(byte[] content, int offset, int len) Factory method for constructingJsonParserthat is properly wired to allow callbacks for deserialization: basically constructs aObjectReadContextand then callsTokenStreamFactory.createParser(ObjectReadContext,byte[],int,int).createParser(char[] content) Factory method for constructingJsonParserthat is properly wired to allow callbacks for deserialization: basically constructs aObjectReadContextand then callsTokenStreamFactory.createParser(ObjectReadContext,char[]).createParser(char[] content, int offset, int len) Factory method for constructingJsonParserthat is properly wired to allow callbacks for deserialization: basically constructs aObjectReadContextand then callsTokenStreamFactory.createParser(ObjectReadContext,char[],int,int).createParser(DataInput content) Factory method for constructingJsonParserthat is properly wired to allow callbacks for deserialization: basically constructs aObjectReadContextand then callsTokenStreamFactory.createParser(ObjectReadContext,DataInput).createParser(File src) Factory method for constructingJsonParserthat is properly wired to allow callbacks for deserialization: basically constructs aObjectReadContextand then callsTokenStreamFactory.createParser(ObjectReadContext,java.io.File).Factory method for constructingJsonParserthat is properly wired to allow callbacks for deserialization: basically constructs aObjectReadContextand then callsTokenStreamFactory.createParser(ObjectReadContext,InputStream).Factory method for constructingJsonParserthat is properly wired to allow callbacks for deserialization: basically constructs aObjectReadContextand then callsTokenStreamFactory.createParser(ObjectReadContext,Reader).createParser(String content) Factory method for constructingJsonParserthat is properly wired to allow callbacks for deserialization: basically constructs aObjectReadContextand then callsTokenStreamFactory.createParser(ObjectReadContext,String).createParser(Path src) Factory method for constructingJsonParserthat is properly wired to allow callbacks for deserialization: basically constructs aObjectReadContextand 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 ofJsonNodeFactorythat this mapper will use when directly constructing rootJsonNodeinstances for Trees.Accessor for getting currently configuredTypeFactoryinstance.booleanbooleanbooleanbooleanMethod for checking whether given datatype-specific feature is enabled.booleanMethod for checking whether given deserialization-specific feature is enabled.booleanMethod for checking whether givenMapperFeatureis enabled.booleanMethod for checking whether given serialization-specific feature is enabled.nullNode()reader()Factory method for constructingObjectReaderwith default settings.reader(Base64Variant defaultBase64) Factory method for constructingObjectReaderthat will use specified Base64 encoding variant for Base64-encoded binary data.reader(FormatSchema schema) Factory method for constructingObjectReaderthat will pass specific schema object toJsonParserused for reading content.reader(ContextAttributes attrs) Factory method for constructingObjectReaderthat will use specified default attributes.reader(DatatypeFeature feature) Factory method for constructingObjectReaderwith specified feature enabled (compared to settings that this mapper instance has).reader(DeserializationFeature feature) Factory method for constructingObjectReaderwith specified feature enabled (compared to settings that this mapper instance has).reader(DeserializationFeature first, DeserializationFeature... other) Factory method for constructingObjectReaderwith specified features enabled (compared to settings that this mapper instance has).reader(InjectableValues injectableValues) Factory method for constructingObjectReaderthat will use specified injectable values.reader(JsonNodeFactory nodeFactory) Factory method for constructingObjectReaderthat will use specifiedJsonNodeFactoryfor constructing JSON trees.Factory method for constructingObjectReaderthat will read or update instances of specified typereaderFor(TypeReference<?> typeRef) Factory method for constructingObjectReaderthat will read or update instances of specified typeFactory method for constructingObjectReaderthat will read or update instances of specified typereaderForArrayOf(Class<?> type) Factory method for constructingObjectReaderthat will read values of a typeList<type>.readerForListOf(Class<?> type) Factory method for constructingObjectReaderthat will read or update instances of a typeList<type>.readerForMapOf(Class<?> type) Factory method for constructingObjectReaderthat will read or update instances of a typeMap<String, type>Functionally same as:readerForUpdating(Object valueToUpdate) Factory method for constructingObjectReaderthat 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 constructingObjectReaderthat will deserialize objects using specified JSON View (filter).protected ObjectreadTree(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 ofJsonNodeinstances.Same asreadTree(InputStream)except content accessed through passed-inReaderSame asreadTree(InputStream)except content read from passed-inStringSame asreadTree(InputStream)except content read from passed-inPath.Method to deserialize JSON content as a treeJsonNode.readTree(TokenBuffer src) Same asreadTree(InputStream)except content read from passed-inTokenBuffer.<T> T<T> TreadValue(byte[] content, int offset, int len, TypeReference<T> valueTypeRef) <T> T<T> T<T> TreadValue(byte[] content, TypeReference<T> valueTypeRef) <T> T<T> T<T> TreadValue(DataInput src, TypeReference<T> valueTypeRef) <T> T<T> TMethod to deserialize JSON content from given file into given Java type.<T> TreadValue(File src, TypeReference<T> valueTypeRef) Method to deserialize JSON content from given file into given Java type.<T> TMethod to deserialize JSON content from given file into given Java type.<T> TreadValue(InputStream src, Class<T> valueType) <T> TreadValue(InputStream src, TypeReference<T> valueTypeRef) <T> TreadValue(InputStream src, JavaType valueType) <T> T<T> TreadValue(Reader src, TypeReference<T> valueTypeRef) <T> T<T> TMethod to deserialize JSON content from given JSON content String.<T> TreadValue(String content, TypeReference<T> valueTypeRef) Method to deserialize JSON content from given JSON content String.<T> TMethod to deserialize JSON content from given JSON content String.<T> TMethod to deserialize JSON content from given path into given Java type.<T> TreadValue(Path src, TypeReference<T> valueTypeRef) Method to deserialize JSON content from given path into given Java type.<T> TMethod to deserialize JSON content from given path into given Java type.<T> TreadValue(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> TreadValue(JsonParser p, ResolvedType valueType) Method to deserialize JSON content into a Java type, reference to which is passed as argument.<T> TreadValue(JsonParser p, TypeReference<T> valueTypeRef) Method to deserialize JSON content into a Java type, reference to which is passed as argument.<T> TreadValue(JsonParser p, JavaType valueType) Type-safe overloaded method, basically alias forreadValue(JsonParser, Class).<T> TreadValue(TokenBuffer src, Class<T> valueType) <T> TreadValue(TokenBuffer src, TypeReference<T> valueTypeRef) <T> TreadValue(TokenBuffer src, JavaType valueType) <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 newMapperBuilderfor constructing differently configuredObjectMapperinstance, starting with current configuration including base settings and registered modules.Method that may be used to find outJacksonModules that were registered when creating this mapper (if any).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 ofTokenStreamFactorythat this mapper uses if it needs to constructJsonParsers and/orJsonGenerators.Method for constructing aJsonParserout of JSON tree representation.<T> TtreeToValue(TreeNode n, Class<T> valueType) Convenience conversion method that will bind data given JSON tree contains into specific value (usually bean) type.<T> TtreeToValue(TreeNode n, TypeReference<T> toValueTypeRef) Same astreeToValue(TreeNode, JavaType)but target type specified using fully resolvedTypeReference.<T> TtreeToValue(TreeNode n, JavaType valueType) Same astreeToValue(TreeNode, Class)but target type specified using fully resolvedJavaType.<T> TupdateValue(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 modelJsonNoderepresentation.version()Method that will return version information stored in and read from jar that contains this class.writer()Convenience method for constructingObjectWriterwith default settings.writer(DateFormat df) Factory method for constructingObjectWriterthat will serialize objects using specifiedDateFormat; or, if null passed, using timestamp (64-bit number.writer(Base64Variant defaultBase64) Factory method for constructingObjectWriterthat will use specified Base64 encoding variant for Base64-encoded binary data.writer(FormatSchema schema) Factory method for constructingObjectWriterthat will pass specific schema object toJsonGeneratorused for writing content.writer(CharacterEscapes escapes) Factory method for constructingObjectReaderthat will use specified character escaping details for output.writer(ContextAttributes attrs) Factory method for constructingObjectWriterthat will use specified default attributes.Factory method for constructingObjectWriterwith specified features enabled (compared to settings that this mapper instance has).writer(FilterProvider filterProvider) Factory method for constructingObjectWriterthat will serialize objects using specified filter provider.writer(SerializationFeature feature) Factory method for constructingObjectWriterwith specified feature enabled (compared to settings that this mapper instance has).writer(SerializationFeature first, SerializationFeature... other) Factory method for constructingObjectWriterwith specified features enabled (compared to settings that this mapper instance has).protected ObjectFactory method for constructingObjectWriterthat will serialize objects using specified root type, instead of actual runtime type of value.writerFor(TypeReference<?> rootType) Factory method for constructingObjectWriterthat will serialize objects using specified root type, instead of actual runtime type of value.Factory method for constructingObjectWriterthat will serialize objects using specified root type, instead of actual runtime type of value.Factory method for constructingObjectWriterthat will serialize objects using the default pretty printer for indentationwriterWithView(Class<?> serializationView) Factory method for constructingObjectWriterthat will serialize objects using specified JSON View (filter).voidwriteTree(JsonGenerator g, TreeNode rootNode) voidwriteValue(DataOutput out, Object value) voidwriteValue(File file, Object value) Method that can be used to serialize any Java value as JSON output, written to File provided.voidwriteValue(OutputStream out, Object value) Method that can be used to serialize any Java value as JSON output, using output stream provided (using encodingJsonEncoding.UTF8).voidwriteValue(Writer w, Object value) Method that can be used to serialize any Java value as JSON output, using Writer provided.voidwriteValue(Path path, Object value) Method that can be used to serialize any Java value as JSON output, written to Path provided.voidwriteValue(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.writeValueIntoBuffer(Object value) Convenience method that can be used to serialize any Java value into newly createdTokenBuffer.
-
Field Details
-
_streamFactory
Factory used to createJsonParserandJsonGeneratorinstances as necessary. -
_typeFactory
Specific factory used for creatingJavaTypeinstances; 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-callSerializationContextinstances. -
_serializationConfig
Configuration object that defines basic global settings for the serialization process -
_deserializationContexts
Factory used for constructing per-callDeserializationContextinstances. -
_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-handlingTokenStreamFactoryas necessary and all other unmodified default settings, and no additional registered modules. -
ObjectMapper
Constructs instance that uses specifiedTokenStreamFactoryfor constructing necessaryJsonParsers and/orJsonGenerators, 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 newMapperBuilderfor constructing differently configuredObjectMapperinstance, 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 ofTokenStreamFactorythat this mapper uses if it needs to constructJsonParsers and/orJsonGenerators.WARNING: note that all
ObjectReaderandObjectWriterinstances 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 ofObjectReaderandObjectWriterfor changingStreamReadFeatureandStreamWriteFeaturesettings to use on per-call basis.- Returns:
TokenStreamFactorythat this mapper uses when it needs to construct Json parser and generators- Since:
- 3.0
-
getNodeFactory
Method that can be used to get hold ofJsonNodeFactorythat this mapper will use when directly constructing rootJsonNodeinstances for Trees.Note: this is just a shortcut for calling
getDeserializationConfig().getNodeFactory()
-
getInjectableValues
-
getTypeFactory
Accessor for getting currently configuredTypeFactoryinstance. -
constructType
Convenience method for constructingJavaTypeout of given type (typicallyjava.lang.Class), but without explicit context. -
constructType
Convenience method for constructingJavaTypeout of given type reference. -
isEnabled
-
isEnabled
-
isEnabled
-
isEnabled
Method for checking whether givenMapperFeatureis enabled. -
isEnabled
Method for checking whether given deserialization-specific feature is enabled. -
isEnabled
Method for checking whether given serialization-specific feature is enabled. -
isEnabled
Method for checking whether given datatype-specific feature is enabled. -
registeredModules
Method that may be used to find outJacksonModules that were registered when creating this mapper (if any).NOTE: in 2.x this method was called
getRegisteredModuleIds()and returned Module identifiers (typicallyStrings); but since 3.0 it returns actualJacksonModuleinstances.- Since:
- 3.0
-
createParser
Factory method for constructingJsonParserthat is properly wired to allow callbacks for deserialization: basically constructs aObjectReadContextand then callsTokenStreamFactory.createParser(ObjectReadContext,java.io.File).- Throws:
JacksonException- Since:
- 3.0
-
createParser
Factory method for constructingJsonParserthat is properly wired to allow callbacks for deserialization: basically constructs aObjectReadContextand then callsTokenStreamFactory.createParser(ObjectReadContext,Path).- Throws:
JacksonException- Since:
- 3.0
-
createParser
Factory method for constructingJsonParserthat is properly wired to allow callbacks for deserialization: basically constructs aObjectReadContextand then callsTokenStreamFactory.createParser(ObjectReadContext,InputStream).- Throws:
JacksonException- Since:
- 3.0
-
createParser
Factory method for constructingJsonParserthat is properly wired to allow callbacks for deserialization: basically constructs aObjectReadContextand then callsTokenStreamFactory.createParser(ObjectReadContext,Reader).- Throws:
JacksonException- Since:
- 3.0
-
createParser
Factory method for constructingJsonParserthat is properly wired to allow callbacks for deserialization: basically constructs aObjectReadContextand then callsTokenStreamFactory.createParser(ObjectReadContext,byte[]).- Throws:
JacksonException- Since:
- 3.0
-
createParser
Factory method for constructingJsonParserthat is properly wired to allow callbacks for deserialization: basically constructs aObjectReadContextand then callsTokenStreamFactory.createParser(ObjectReadContext,byte[],int,int).- Throws:
JacksonException- Since:
- 3.0
-
createParser
Factory method for constructingJsonParserthat is properly wired to allow callbacks for deserialization: basically constructs aObjectReadContextand then callsTokenStreamFactory.createParser(ObjectReadContext,String).- Throws:
JacksonException- Since:
- 3.0
-
createParser
Factory method for constructingJsonParserthat is properly wired to allow callbacks for deserialization: basically constructs aObjectReadContextand then callsTokenStreamFactory.createParser(ObjectReadContext,char[]).- Throws:
JacksonException- Since:
- 3.0
-
createParser
Factory method for constructingJsonParserthat is properly wired to allow callbacks for deserialization: basically constructs aObjectReadContextand then callsTokenStreamFactory.createParser(ObjectReadContext,char[],int,int).- Throws:
JacksonException- Since:
- 3.0
-
createParser
Factory method for constructingJsonParserthat is properly wired to allow callbacks for deserialization: basically constructs aObjectReadContextand then callsTokenStreamFactory.createParser(ObjectReadContext,DataInput).- Throws:
JacksonException- Since:
- 3.0
-
createNonBlockingByteArrayParser
Factory method for constructing non-blockingJsonParserthat is properly wired to allow configuration access (and, if relevant for parser, callbacks): essentially constructs aObjectReadContextand then callsTokenStreamFactory.createNonBlockingByteArrayParser(ObjectReadContext).- Throws:
JacksonException- Since:
- 3.0
-
createNonBlockingByteBufferParser
Factory method for constructing non-blockingJsonParserthat is properly wired to allow configuration access (and, if relevant for parser, callbacks): essentially constructs aObjectReadContextand then callsTokenStreamFactory.createNonBlockingByteBufferParser(ObjectReadContext).- Throws:
JacksonException- Since:
- 3.0
-
createGenerator
Factory method for constructingJsonGeneratorthat is properly wired to allow callbacks for serialization: basically constructs aObjectWriteContextand then callsTokenStreamFactory.createGenerator(ObjectWriteContext,OutputStream).- Throws:
JacksonException- Since:
- 3.0
-
createGenerator
Factory method for constructingJsonGeneratorthat is properly wired to allow callbacks for serialization: basically constructs aObjectWriteContextand then callsTokenStreamFactory.createGenerator(ObjectWriteContext,OutputStream,JsonEncoding).- Throws:
JacksonException- Since:
- 3.0
-
createGenerator
Factory method for constructingJsonGeneratorthat is properly wired to allow callbacks for serialization: basically constructs aObjectWriteContextand then callsTokenStreamFactory.createGenerator(ObjectWriteContext,Writer).- Throws:
JacksonException- Since:
- 3.0
-
createGenerator
Factory method for constructingJsonGeneratorthat is properly wired to allow callbacks for serialization: basically constructs aObjectWriteContextand then callsTokenStreamFactory.createGenerator(ObjectWriteContext,File,JsonEncoding).- Throws:
JacksonException- Since:
- 3.0
-
createGenerator
Factory method for constructingJsonGeneratorthat is properly wired to allow callbacks for serialization: basically constructs aObjectWriteContextand then callsTokenStreamFactory.createGenerator(ObjectWriteContext,Path,JsonEncoding).- Throws:
JacksonException- Since:
- 3.0
-
createGenerator
Factory method for constructingJsonGeneratorthat is properly wired to allow callbacks for serialization: basically constructs aObjectWriteContextand then callsTokenStreamFactory.createGenerator(ObjectWriteContext,DataOutput).- Throws:
JacksonException- Since:
- 3.0
-
createObjectNode
Note: return type is co-variant, as basic
TreeCodecabstraction cannot refer to concrete node types (as it's part of core package, whereas impls are part of mapper package)- Specified by:
createObjectNodein interfaceTreeCodec
-
createArrayNode
Note: return type is co-variant, as basic
TreeCodecabstraction cannot refer to concrete node types (as it's part of core package, whereas impls are part of mapper package)- Specified by:
createArrayNodein interfaceTreeCodec
-
booleanNode
- Specified by:
booleanNodein interfaceTreeCodec
-
stringNode
- Specified by:
stringNodein interfaceTreeCodec
-
missingNode
- Specified by:
missingNodein interfaceTreeCodec
-
nullNode
-
treeAsTokens
Method for constructing aJsonParserout of JSON tree representation.- Specified by:
treeAsTokensin interfaceTreeCodec- Parameters:
n- Root node of the tree that resulting parser will read from
-
readTree
Method to deserialize JSON content as a treeJsonNode. ReturnsJsonNodethat represents the root of the resulting tree, if there was content to read, ornullif no more content is accessible via passedJsonParser.NOTE! Behavior with end-of-input (no more content) differs between this
readTreemethod, and all other methods that take input source: latter will return "missing node", NOTnull- Specified by:
readTreein interfaceTreeCodec- Returns:
- a
JsonNode, if valid JSON content found; null if input has no content to bind -- note, however, that if JSONnulltoken is found, it will be represented as a non-nullJsonNode(one that returnstrueforJsonNode.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_EXCEPTIONSdoes NOT result in wrapping of exception even if enabled)StreamReadException- if underlying input contains invalid content of typeJsonParsersupports (JSON for default case)JacksonException
-
writeTree
- Specified by:
writeTreein 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 (
CollectionorMap. 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_EXCEPTIONSdoes NOT result in wrapping of exception even if enabled)StreamReadException- if underlying input contains invalid content of typeJsonParsersupports (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_EXCEPTIONSdoes NOT result in wrapping of exception even if enabled)StreamReadException- if underlying input contains invalid content of typeJsonParsersupports (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_EXCEPTIONSdoes NOT result in wrapping of exception even if enabled)StreamReadException- if underlying input contains invalid content of typeJsonParsersupports (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_EXCEPTIONSdoes NOT result in wrapping of exception even if enabled)StreamReadException- if underlying input contains invalid content of typeJsonParsersupports (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
JsonParserMUST 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
ObjectReaderhas 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 ofJsonNodeinstances. 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
IOExceptionwill be thrown. If a parsing problem occurs (invalid JSON),StreamReadExceptionwill be thrown. If no content is found from input (end-of-input), Javanullwill 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 JSONnulltoken is found, it will be represented as a non-nullJsonNode(one that returnstrueforJsonNode.isNull() - Throws:
StreamReadException- if underlying input contains invalid content of typeJsonParsersupports (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
-
readTree
Same asreadTree(InputStream)except content read from passed-inTokenBuffer.- 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 modelJsonNoderepresentation. Functionally similar to serializing value into token stream and parsing that stream back as tree model node, but more efficient asTokenBufferis 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 basicJsonNodeorObjectNode- Parameters:
fromValue- Java value to convert- Returns:
- (non-null) Root node of the resulting content tree: in case of
nullvalue 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_EXCEPTIONSdoes NOT result in wrapping of exception even if enabled)StreamReadException- if underlying input contains invalid content of typeJsonParsersupports (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_EXCEPTIONSdoes NOT result in wrapping of exception even if enabled)StreamReadException- if underlying input contains invalid content of typeJsonParsersupports (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_EXCEPTIONSdoes NOT result in wrapping of exception even if enabled)StreamReadException- if underlying input contains invalid content of typeJsonParsersupports (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_EXCEPTIONSdoes NOT result in wrapping of exception even if enabled)StreamReadException- if underlying input contains invalid content of typeJsonParsersupports (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_EXCEPTIONSdoes NOT result in wrapping of exception even if enabled)StreamReadException- if underlying input contains invalid content of typeJsonParsersupports (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_EXCEPTIONSdoes NOT result in wrapping of exception even if enabled)StreamReadException- if underlying input contains invalid content of typeJsonParsersupports (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 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_EXCEPTIONSdoes NOT result in wrapping of exception even if enabled)StreamReadException- if underlying input contains invalid content of typeJsonParsersupports (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_EXCEPTIONSdoes NOT result in wrapping of exception even if enabled)StreamReadException- if underlying input contains invalid content of typeJsonParsersupports (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_EXCEPTIONSdoes NOT result in wrapping of exception even if enabled)StreamReadException- if underlying input contains invalid content of typeJsonParsersupports (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
-
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,
TokenStreamFactorythis mapper uses may choose to close the stream depending on its settings (by default, it will try to close it whenJsonGeneratorwe 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,
TokenStreamFactorythis mapper uses may choose to close the stream depending on its settings (by default, it will try to close it whenJsonGeneratorwe 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)withStringWriterand 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)withByteArrayOutputStreamand getting bytes, but more efficient. Encoding used will be UTF-8.- Throws:
JacksonException
-
writeValueIntoBuffer
Convenience method that can be used to serialize any Java value into newly createdTokenBuffer. Functionally equivalent to callingwriteValue(JsonGenerator, Object)passing buffer as generator.- 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 isCloseableand itsclose()method is to be called right after serialization has been called- Throws:
JacksonException
-
writer
Convenience method for constructingObjectWriterwith default settings. -
writer
Factory method for constructingObjectWriterwith specified feature enabled (compared to settings that this mapper instance has). -
writer
Factory method for constructingObjectWriterwith specified features enabled (compared to settings that this mapper instance has). -
writer
Factory method for constructingObjectWriterwith specified features enabled (compared to settings that this mapper instance has). -
writer
Factory method for constructingObjectWriterthat will serialize objects using specifiedDateFormat; or, if null passed, using timestamp (64-bit number. -
writerWithView
Factory method for constructingObjectWriterthat will serialize objects using specified JSON View (filter). -
writerFor
Factory method for constructingObjectWriterthat 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 constructingObjectWriterthat 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 constructingObjectWriterthat 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 constructingObjectWriterthat will serialize objects using the default pretty printer for indentation -
writer
Factory method for constructingObjectWriterthat will serialize objects using specified filter provider. -
writer
Factory method for constructingObjectWriterthat will pass specific schema object toJsonGeneratorused for writing content.- Parameters:
schema- Schema to pass to generator
-
writer
Factory method for constructingObjectWriterthat will use specified Base64 encoding variant for Base64-encoded binary data. -
writer
Factory method for constructingObjectReaderthat will use specified character escaping details for output. -
writer
Factory method for constructingObjectWriterthat will use specified default attributes. -
reader
Factory method for constructingObjectReaderwith default settings. Note that the resulting instance is NOT usable as is, without defining expected value type. -
reader
Factory method for constructingObjectReaderwith 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 constructingObjectReaderwith 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. -
reader
Factory method for constructingObjectReaderwith 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. -
readerForUpdating
Factory method for constructingObjectReaderthat 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 constructingObjectReaderthat will read or update instances of specified type -
readerFor
Factory method for constructingObjectReaderthat will read or update instances of specified type -
readerFor
Factory method for constructingObjectReaderthat will read or update instances of specified type -
readerForArrayOf
Factory method for constructingObjectReaderthat will read values of a typeList<type>. Functionally same as:readerFor(type[].class); -
readerForListOf
Factory method for constructingObjectReaderthat will read or update instances of a typeList<type>. Functionally same as:readerFor(new TypeReference<List<type>>() { }); -
readerForMapOf
Factory method for constructingObjectReaderthat 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 constructingObjectReaderthat will use specifiedJsonNodeFactoryfor constructing JSON trees. -
reader
Factory method for constructingObjectReaderthat will pass specific schema object toJsonParserused for reading content.- Parameters:
schema- Schema to pass to parser
-
reader
Factory method for constructingObjectReaderthat will use specified injectable values.- Parameters:
injectableValues- Injectable values to use
-
readerWithView
Factory method for constructingObjectReaderthat will deserialize objects using specified JSON View (filter). -
reader
Factory method for constructingObjectReaderthat will use specified Base64 encoding variant for Base64-encoded binary data. -
reader
Factory method for constructingObjectReaderthat 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 explicitwriteValueandreadValuemethods.- Throws:
JacksonException
-
updateValue
Convenience method similar toconvertValue(Object, JavaType)but one in whichImplementation is approximately as follows:
- Serialize `updateWithValue` into
TokenBuffer - Construct
ObjectReaderwith `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 usesSerializerhierarchy 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 constructingSerializationContextto 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 forJsonNodereading.- Throws:
JacksonException
-
_deserializationContext
Internal helper method called to create an instance ofDeserializationContextfor 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 produceObjectReaderinstances 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 produceObjectReaderinstances of proper sub-type -
_newWriter
Factory method sub-classes must override, to produceObjectWriterinstances of proper sub-type -
_newWriter
Factory method sub-classes must override, to produceObjectWriterinstances of proper sub-type -
_newWriter
Factory method sub-classes must override, to produceObjectWriterinstances 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
-