Class ObjectMapper
- All Implemented Interfaces:
Versioned
JsonParser
and JsonGenerator
for implementing actual reading/writing of JSON.
The main conversion API is defined in ObjectCodec
, so that
implementation details of this class need not be exposed to
streaming parser and generator classes.
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).
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
CustomizedTypeResolverBuilder
that provides type resolver builders used with so-called "default typing" (seeenableDefaultTyping()
for details).static enum
Enumeration used withenableDefaultTyping()
to specify what kind of types (classes) default typing should be used for. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected DeserializationConfig
Configuration object that defines basic global settings for the serialization processprotected DeserializerProvider
Object that manages access to deserializers used for deserializing JSON content into Java objects, including possible caching of the deserializers.protected InjectableValues
Provider for values to inject in deserialized POJOs.protected final JsonFactory
Factory used to createJsonParser
andJsonGenerator
instances as necessary.protected final ConcurrentHashMap<JavaType,
JsonDeserializer<Object>> We will use a separate main-level Map for keeping track of root-level deserializers.protected SerializationConfig
Configuration object that defines basic global settings for the serialization processprotected SerializerFactory
Serializer factory used for constructing serializers.protected SerializerProvider
Object that manages access to serializers used for serialization, including caching.protected SubtypeResolver
Registered concrete subtypes that can be used instead of (or in addition to) ones declared using annotations.protected 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)protected static final AnnotationIntrospector
protected static final ClassIntrospector<? extends BeanDescription>
protected static final VisibilityChecker<?>
-
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor, which will construct the defaultJsonFactory
as necessary, useStdSerializerProvider
as itsSerializerProvider
, andBeanSerializerFactory
as itsSerializerFactory
.Construct mapper that uses specifiedJsonFactory
for constructing necessaryJsonParser
s and/orJsonGenerator
s.ObjectMapper
(JsonFactory jf, SerializerProvider sp, DeserializerProvider dp, SerializationConfig sconfig, DeserializationConfig dconfig) Deprecated. -
Method Summary
Modifier and TypeMethodDescriptionprotected final void
_configAndWriteValue
(JsonGenerator jgen, Object value) Method called to configure the generator as necessary and then call write functionalityprotected final void
_configAndWriteValue
(JsonGenerator jgen, Object value, Class<?> viewClass) protected Object
protected DeserializationContext
protected PrettyPrinter
Helper method that should return default pretty-printer to use for generators constructed by this mapper, when instructed to use default pretty printer.protected JsonDeserializer<Object>
_findRootDeserializer
(DeserializationConfig cfg, JavaType valueType) Method called to locate deserializer for the passed root-level value.protected JsonToken
Method called to ensure that given parser is ready for reading content for data binding.protected Object
_readMapAndClose
(JsonParser jp, JavaType valueType) protected Object
_readValue
(DeserializationConfig cfg, JsonParser jp, JavaType valueType) Actual implementation of value reading+binding operation.protected Object
_unwrapAndDeserialize
(JsonParser jp, JavaType rootType, DeserializationContext ctxt, JsonDeserializer<Object> deser) boolean
canDeserialize
(JavaType type) Method that can be called to check whether mapper thinks it could deserialize an Object of given type.boolean
canSerialize
(Class<?> type) Method that can be called to check whether mapper thinks it could serialize an instance of given Class.configure
(JsonGenerator.Feature f, boolean state) Method for changing state of an on/offJsonGenerator
feature forJsonFactory
instance this object mapper uses.configure
(JsonParser.Feature f, boolean state) Method for changing state of an on/offJsonParser
feature forJsonFactory
instance this object mapper uses.configure
(DeserializationConfig.Feature f, boolean state) Method for changing state of an on/off deserialization feature for this object mapper.configure
(SerializationConfig.Feature f, boolean state) Method for changing state of an on/off serialization feature for this object mapper.Convenience method for constructingJavaType
out of given type (typicallyjava.lang.Class
), but without explicit context.<T> T
convertValue
(Object fromValue, Class<T> toValueType) Convenience method for doing two-step conversion from given value, into instance of given value type.<T> T
convertValue
(Object fromValue, JavaType toValueType) <T> T
convertValue
(Object fromValue, TypeReference toValueTypeRef) Method that creates a copy of the shared defaultDeserializationConfig
object that defines configuration settings for deserialization.Method that creates a copy of the shared defaultSerializationConfig
object that defines configuration settings for serialization.Note: return type is co-variant, as basic ObjectCodec abstraction can not refer to concrete node types (as it's part of core package, whereas impls are part of mapper package)Note: return type is co-variant, as basic ObjectCodec abstraction can not refer to concrete node types (as it's part of core package, whereas impls are part of mapper package)Deprecated.Since 1.9, usewriterWithDefaultPrettyPrinter()
instead.Method for enabling specifiedDeserializationConfig
features.Method for enabling specifiedDeserializationConfig
features.Method for disabling automatic inclusion of type information; if so, only explicitly annotated types (ones withJsonTypeInfo
) will have additional embedded type information.Method for enabling specifiedDeserializationConfig
features.Method for enabling specifiedDeserializationConfig
features.Convenience method that is equivalent to callingConvenience method that is equivalent to callingenableDefaultTyping
(ObjectMapper.DefaultTyping applicability, JsonTypeInfo.As includeAs) Method for enabling automatic inclusion of type information, needed for proper deserialization of polymorphic types (unless types have been annotated withJsonTypeInfo
).enableDefaultTypingAsProperty
(ObjectMapper.DefaultTyping applicability, String propertyName) Method for enabling automatic inclusion of type information -- needed for proper deserialization of polymorphic types (unless types have been annotated withJsonTypeInfo
) -- using "As.PROPERTY" inclusion mechanism and specified property name to use for inclusion (default being "@class" since default type information always uses class name as type identifier)filteredWriter
(FilterProvider filterProvider) Deprecated.Since 1.9, usewriter(FilterProvider)
instead.generateJsonSchema
(Class<?> t) Generate Json-schema instance for specified class.generateJsonSchema
(Class<?> t, SerializationConfig cfg) Generate Json-schema instance for specified class, using specific serialization configurationMethod that returns the shared defaultDeserializationConfig
object that defines configuration settings for deserialization.Method that can be used to get hold ofJsonFactory
that this mapper uses if it needs to constructJsonParser
s and/orJsonGenerator
s.Method that can be used to get hold ofJsonNodeFactory
that this mapper will use when directly constructing rootJsonNode
instances for Trees.Method that returns the shared defaultSerializationConfig
object that defines configuration settings for serialization.Method for accessing subtype resolver in use.Accessor for getting currently configuredTypeFactory
instance.Method for accessing currently configured visibility checker; object used for determining whether given property element (method, field, constructor) can be auto-detected or not.boolean
Convenience method, equivalent to:boolean
Convenience method, equivalent to:boolean
Convenience method, equivalent to:boolean
Convenience method, equivalent to:Deprecated.Since 1.9, usewriter(FilterProvider)
instead.reader()
Factory method for constructingObjectReader
with default settings.Factory method for constructingObjectReader
that will read or update instances of specified typereader
(FormatSchema schema) Factory method for constructingObjectReader
that will pass specific schema object toJsonParser
used for reading content.reader
(InjectableValues injectableValues) Factory method for constructingObjectReader
that will use specified injectable values.Factory method for constructingObjectReader
that will use specifiedJsonNodeFactory
for constructing JSON trees.Factory method for constructingObjectReader
that will read or update instances of specified typereader
(TypeReference<?> type) Factory method for constructingObjectReader
that will read or update instances of specified typereaderForUpdating
(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.readTree
(byte[] content) Method to deserialize JSON content as tree expressed using set ofJsonNode
instances.Method to deserialize JSON content as tree expressed using set ofJsonNode
instances.readTree
(InputStream in) Method to deserialize JSON content as tree expressed using set ofJsonNode
instances.Method to deserialize JSON content as tree expressed using set ofJsonNode
instances.Method to deserialize JSON content as tree expressed using set ofJsonNode
instances.Method to deserialize JSON content as tree expressed using set ofJsonNode
instances.readTree
(JsonParser jp) Method to deserialize JSON content as tree expressed using set ofJsonNode
instances.readTree
(JsonParser jp, DeserializationConfig cfg) Method to deserialize JSON content as tree expressed using set ofJsonNode
instances.<T> T
<T> T
<T> T
readValue
(byte[] src, int offset, int len, TypeReference valueTypeRef) <T> T
<T> T
<T> T
readValue
(byte[] src, TypeReference valueTypeRef) <T> T
<T> T
<T> T
readValue
(File src, TypeReference valueTypeRef) <T> T
readValue
(InputStream src, Class<T> valueType) <T> T
readValue
(InputStream src, JavaType valueType) <T> T
readValue
(InputStream src, TypeReference valueTypeRef) <T> T
<T> T
<T> T
readValue
(Reader src, TypeReference valueTypeRef) <T> T
<T> T
<T> T
readValue
(String content, TypeReference valueTypeRef) <T> T
<T> T
<T> T
readValue
(URL src, TypeReference valueTypeRef) <T> T
Convenience method for converting results from given JSON tree into given value type.<T> T
Convenience method for converting results from given JSON tree into given value type.<T> T
readValue
(JsonNode root, TypeReference valueTypeRef) Convenience method for converting results from given JSON tree into given value type.<T> T
readValue
(JsonParser jp, 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
).<T> T
readValue
(JsonParser jp, Class<T> valueType, DeserializationConfig cfg) 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
).<T> T
readValue
(JsonParser jp, JavaType valueType) Method to deserialize JSON content into a Java type, reference to which is passed as argument.<T> T
readValue
(JsonParser jp, JavaType valueType, DeserializationConfig cfg) Method to deserialize JSON content into a Java type, reference to which is passed as argument.<T> T
readValue
(JsonParser jp, TypeReference<?> valueTypeRef) Method to deserialize JSON content into a Java type, reference to which is passed as argument.<T> T
readValue
(JsonParser jp, TypeReference<?> valueTypeRef, DeserializationConfig cfg) Method to deserialize JSON content into a Java type, reference to which is passed as argument.<T> MappingIterator<T>
readValues
(JsonParser jp, Class<T> valueType) Method for reading sequence of Objects from parser stream.<T> MappingIterator<T>
readValues
(JsonParser jp, JavaType valueType) Method for reading sequence of Objects from parser stream.<T> MappingIterator<T>
readValues
(JsonParser jp, TypeReference<?> valueTypeRef) Method for reading sequence of Objects from parser stream.void
registerModule
(Module module) Method for registering a module that can extend functionality provided by this mapper; for example, by adding providers for custom serializers and deserializers.void
registerSubtypes
(Class<?>... classes) Method for registering specified class as a subtype, so that typename-based resolution can link supertypes to subtypes (as an alternative to using annotations).void
registerSubtypes
(NamedType... types) Method for registering specified class as a subtype, so that typename-based resolution can link supertypes to subtypes (as an alternative to using annotations).schemaBasedReader
(FormatSchema schema) Deprecated.Since 1.9, usereader(FormatSchema)
instead.schemaBasedWriter
(FormatSchema schema) Deprecated.Since 1.9, usewriter(FilterProvider)
instead.Method for changingAnnotationIntrospector
used by this mapper instance for both serialization and deserializationvoid
setDateFormat
(DateFormat dateFormat) Method for configuring the defaultDateFormat
to use when serializing time values as Strings, and deserializing from JSON Strings.setDefaultTyping
(TypeResolverBuilder<?> typer) Method for enabling automatic inclusion of type information, using specified handler object for determining which types this affects, as well as details of how information is embedded.Method for replacing the shared default deserialization configuration object.Method for setting specificDeserializerProvider
to use for handling caching ofJsonDeserializer
instances.void
setFilters
(FilterProvider filterProvider) Convenience method that is equivalent to:void
Method for configuringHandlerInstantiator
to use for creating instances of handlers (such as serializers, deserializers, type and type id resolvers), given a class.setInjectableValues
(InjectableValues injectableValues) Method for specifyingJsonNodeFactory
to use for constructing root level tree nodes (via methodcreateObjectNode()
Method for setting custom property naming strategy to use.Method for replacing the shared default serialization configuration object.Method for setting defalt POJO property inclusion strategy for serialization.Method for setting specificSerializerFactory
to use for constructing (bean) serializers.Method for setting specificSerializerProvider
to use for handling caching ofJsonSerializer
instances.void
Method for setting custom subtype resolver to use.Method that can be used to overrideTypeFactory
instance used by this mapper.setVisibility
(JsonMethod forMethod, JsonAutoDetect.Visibility visibility) Convenience method that allows changing configuration for underlyingVisibilityChecker
s, to change details of what kinds of properties are auto-detected.void
Method for setting currently configured visibility checker; object used for determining whether given property element (method, field, constructor) can be auto-detected or not.Method for constructing aJsonParser
out of JSON tree representation.<T> T
treeToValue
(JsonNode n, Class<T> valueType) Convenience conversion method that will bind data given JSON tree contains into specific value (usually bean) type.typedWriter
(Class<?> rootType) Deprecated.Since 1.9, usewriterWithType(Class)
instead.typedWriter
(JavaType rootType) Deprecated.Since 1.9, usewriterWithType(JavaType)
instead.typedWriter
(TypeReference<?> rootType) Deprecated.Since 1.9, usewriterWithType(TypeReference)
instead.updatingReader
(Object valueToUpdate) Deprecated.Since 1.9, usereaderForUpdating(java.lang.Object)
instead.<T extends JsonNode>
TvalueToTree
(Object fromValue) Reverse oftreeToValue(org.codehaus.jackson.JsonNode, java.lang.Class<T>)
; given a value (usually bean), will construct equivalent JSON Tree representation.version()
Method that will return version information stored in and read from jar that contains this class.viewWriter
(Class<?> serializationView) Deprecated.Since 1.9, usewriterWithView(Class)
instead.withModule
(Module module) Fluent-style alternative toregisterModule(org.codehaus.jackson.map.Module)
; functionally equivalent to: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
(FormatSchema schema) Factory method for constructingObjectWriter
that will pass specific schema object toJsonGenerator
used for writing content.writer
(FilterProvider filterProvider) Factory method for constructingObjectWriter
that will serialize objects using specified filter provider.writer
(PrettyPrinter pp) Factory method for constructingObjectWriter
that will serialize objects using specified pretty printer for indentation (or if null, no pretty printer)Factory method for constructingObjectWriter
that will serialize objects using the default pretty printer for indentationwriterWithType
(Class<?> rootType) Factory method for constructingObjectWriter
that will serialize objects using specified root type, instead of actual runtime type of value.writerWithType
(JavaType rootType) Factory method for constructingObjectWriter
that will serialize objects using specified root type, instead of actual runtime type of value.writerWithType
(TypeReference<?> rootType) Factory method for constructingObjectWriter
that will serialize objects using specified root type, instead of actual runtime type of value.writerWithView
(Class<?> serializationView) Factory method for constructingObjectWriter
that will serialize objects using specified JSON View (filter).void
writeTree
(JsonGenerator jgen, JsonNode rootNode) Method to serialize given JSON Tree, using generator provided.void
writeTree
(JsonGenerator jgen, JsonNode rootNode, SerializationConfig cfg) Method to serialize given Json Tree, using generator provided.void
writeValue
(File resultFile, 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
(JsonGenerator jgen, Object value) Method that can be used to serialize any Java value as JSON output, using providedJsonGenerator
.void
writeValue
(JsonGenerator jgen, Object value, SerializationConfig config) Method that can be used to serialize any Java value as JSON output, using providedJsonGenerator
, configured as per passed configuration object.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
-
DEFAULT_INTROSPECTOR
-
DEFAULT_ANNOTATION_INTROSPECTOR
-
STD_VISIBILITY_CHECKER
- Since:
- 1.5
-
_jsonFactory
Factory used to createJsonParser
andJsonGenerator
instances as necessary. -
_subtypeResolver
Registered concrete subtypes that can be used instead of (or in addition to) ones declared using annotations.- Since:
- 1.6
-
_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.- Since:
- 1.9
-
_serializationConfig
Configuration object that defines basic global settings for the serialization process -
_serializerProvider
Object that manages access to serializers used for serialization, including caching. It is configured with_serializerFactory
to allow for constructing custom serializers. -
_serializerFactory
Serializer factory used for constructing serializers. -
_deserializationConfig
Configuration object that defines basic global settings for the serialization process -
_deserializerProvider
Object that manages access to deserializers used for deserializing JSON content into Java objects, including possible caching of the deserializers. It contains a reference toDeserializerFactory
to use for constructing acutal deserializers. -
_rootDeserializers
We will use a separate main-level Map for keeping track of root-level deserializers. This is where most succesful 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.
Since version 1.5, these may are either "raw" deserializers (when no type information is needed for base type), or type-wrapped deserializers (if it is needed)
-
-
Constructor Details
-
ObjectMapper
public ObjectMapper()Default constructor, which will construct the defaultJsonFactory
as necessary, useStdSerializerProvider
as itsSerializerProvider
, andBeanSerializerFactory
as itsSerializerFactory
. This means that it can serialize all standard JDK types, as well as regular Java Beans (based on method names and Jackson-specific annotations), but does not support JAXB annotations. -
ObjectMapper
Construct mapper that uses specifiedJsonFactory
for constructing necessaryJsonParser
s and/orJsonGenerator
s. -
ObjectMapper
Deprecated.Use other constructors instead; note that you can just set serializer factory withsetSerializerFactory(org.codehaus.jackson.map.SerializerFactory)
Construct mapper that uses specifiedSerializerFactory
for constructing necessary serializers. -
ObjectMapper
-
ObjectMapper
public ObjectMapper(JsonFactory jf, SerializerProvider sp, DeserializerProvider dp, SerializationConfig sconfig, DeserializationConfig dconfig) - Parameters:
jf
- JsonFactory to use: if null, a newMappingJsonFactory
will be constructedsp
- SerializerProvider to use: if null, aStdSerializerProvider
will be constructeddp
- DeserializerProvider to use: if null, aStdDeserializerProvider
will be constructedsconfig
- Serialization configuration to use; if null, basicSerializationConfig
will be constructeddconfig
- Deserialization configuration to use; if null, basicDeserializationConfig
will be constructed
-
-
Method Details
-
version
Method that will return version information stored in and read from jar that contains this class. -
registerModule
Method for registering a module that can extend functionality provided by this mapper; for example, by adding providers for custom serializers and deserializers.- Parameters:
module
- Module to register- Since:
- 1.7
-
withModule
Fluent-style alternative toregisterModule(org.codehaus.jackson.map.Module)
; functionally equivalent to:mapper.registerModule(module); return mapper;
NOTE: name is unfortunately misleading in suggesting that a new instance might be created (as is the case with most other 'withXxx()' methods for Jackson core objects) -- this is not the case; rather, this is just a variant ofregisterModule(org.codehaus.jackson.map.Module)
but one that returns 'this' (like it should return, but does not for historical reasons).- Since:
- 1.8
-
getSerializationConfig
Method that returns the shared defaultSerializationConfig
object that defines configuration settings for serialization. Returned object is "live" meaning that changes will be used for future serialization operations for this mapper when using mapper's default configuration -
copySerializationConfig
Method that creates a copy of the shared defaultSerializationConfig
object that defines configuration settings for serialization. Since it is a copy, any changes made to the configuration object will NOT directly affect serialization done using basic serialization methods that use the shared object (that is, ones that do not take separateSerializationConfig
argument.The use case is that of changing object settings of the configuration (like date format being used, see
SerializationConfig.setDateFormat(java.text.DateFormat)
). -
setSerializationConfig
Method for replacing the shared default serialization configuration object. -
getDeserializationConfig
Method that returns the shared defaultDeserializationConfig
object that defines configuration settings for deserialization. Returned object is "live" meaning that changes will be used for future deserialization operations for this mapper when using mapper's default configuration -
copyDeserializationConfig
Method that creates a copy of the shared defaultDeserializationConfig
object that defines configuration settings for deserialization. Since it is a copy, any changes made to the configuration object will NOT directly affect deserialization done using basic deserialization methods that use the shared object (that is, ones that do not take separateDeserializationConfig
argument.The use case is that of changing object settings of the configuration (like deserialization problem handler, see
DeserializationConfig.addHandler(org.codehaus.jackson.map.DeserializationProblemHandler)
) -
setDeserializationConfig
Method for replacing the shared default deserialization configuration object. -
setSerializerFactory
Method for setting specificSerializerFactory
to use for constructing (bean) serializers. -
setSerializerProvider
Method for setting specificSerializerProvider
to use for handling caching ofJsonSerializer
instances. -
getSerializerProvider
- Since:
- 1.4
-
setDeserializerProvider
Method for setting specificDeserializerProvider
to use for handling caching ofJsonDeserializer
instances. -
getDeserializerProvider
- Since:
- 1.4
-
getVisibilityChecker
Method for accessing currently configured visibility checker; object used for determining whether given property element (method, field, constructor) can be auto-detected or not.- Since:
- 1.5
-
setVisibilityChecker
Method for setting currently configured visibility checker; object used for determining whether given property element (method, field, constructor) can be auto-detected or not. This default checker is used if no per-class overrides are defined.- Since:
- 1.5
-
setVisibility
Convenience method that allows changing configuration for underlyingVisibilityChecker
s, to change details of what kinds of properties are auto-detected. Basically short cut for doing:mapper.setVisibilityChecker( mapper.getVisibilityChecker().withVisibility(forMethod, visibility) );
one common use case would be to do:mapper.setVisibility(JsonMethod.FIELD, Visibility.ANY);
which would make all member fields serializable without further annotations, instead of just public fields (default setting).- Parameters:
forMethod
- Type of property descriptor affected (field, getter/isGetter, setter, creator)visibility
- Minimum visibility to require for the property descriptors of type- Returns:
- Modified mapper instance (that is, "this"), to allow chaining of configuration calls
- Since:
- 1.9
-
getSubtypeResolver
Method for accessing subtype resolver in use.- Since:
- 1.6
-
setSubtypeResolver
Method for setting custom subtype resolver to use.- Since:
- 1.6
-
setAnnotationIntrospector
Method for changingAnnotationIntrospector
used by this mapper instance for both serialization and deserialization- Since:
- 1.8
-
setPropertyNamingStrategy
Method for setting custom property naming strategy to use.- Since:
- 1.8
-
setSerializationInclusion
Method for setting defalt POJO property inclusion strategy for serialization. Equivalent to:mapper.setSerializationConfig(mapper.getSerializationConfig().withSerializationInclusion(incl));
- Since:
- 1.9
-
enableDefaultTyping
Convenience method that is equivalent to callingenableObjectTyping(DefaultTyping.OBJECT_AND_NON_CONCRETE);
-
enableDefaultTyping
Convenience method that is equivalent to callingenableObjectTyping(dti, JsonTypeInfo.As.WRAPPER_ARRAY);
-
enableDefaultTyping
public ObjectMapper enableDefaultTyping(ObjectMapper.DefaultTyping applicability, JsonTypeInfo.As includeAs) Method for enabling automatic inclusion of type information, needed for proper deserialization of polymorphic types (unless types have been annotated withJsonTypeInfo
).- Parameters:
applicability
- Defines kinds of types for which additional type information is added; seeObjectMapper.DefaultTyping
for more information.
-
enableDefaultTypingAsProperty
public ObjectMapper enableDefaultTypingAsProperty(ObjectMapper.DefaultTyping applicability, String propertyName) Method for enabling automatic inclusion of type information -- needed for proper deserialization of polymorphic types (unless types have been annotated withJsonTypeInfo
) -- using "As.PROPERTY" inclusion mechanism and specified property name to use for inclusion (default being "@class" since default type information always uses class name as type identifier)- Since:
- 1.7
-
disableDefaultTyping
Method for disabling automatic inclusion of type information; if so, only explicitly annotated types (ones withJsonTypeInfo
) will have additional embedded type information. -
setDefaultTyping
Method for enabling automatic inclusion of type information, using specified handler object for determining which types this affects, as well as details of how information is embedded.- Parameters:
typer
- Type information inclusion handler
-
registerSubtypes
Method for registering specified class as a subtype, so that typename-based resolution can link supertypes to subtypes (as an alternative to using annotations). Type for given class is determined from appropriate annotation; or if missing, default name (unqualified class name)- Since:
- 1.6
-
registerSubtypes
Method for registering specified class as a subtype, so that typename-based resolution can link supertypes to subtypes (as an alternative to using annotations). Name may be provided as part of argument, but if not will be based on annotations or use default name (unqualified class name).- Since:
- 1.6
-
getTypeFactory
Accessor for getting currently configuredTypeFactory
instance.- Since:
- 1.8
-
setTypeFactory
Method that can be used to overrideTypeFactory
instance used by this mapper.Note: will also set
TypeFactory
that deserialization and serialization config objects use. -
constructType
Convenience method for constructingJavaType
out of given type (typicallyjava.lang.Class
), but without explicit context.- Since:
- 1.8
-
setNodeFactory
Method for specifyingJsonNodeFactory
to use for constructing root level tree nodes (via methodcreateObjectNode()
- Since:
- 1.2
-
setFilters
Convenience method that is equivalent to:mapper.setFilters(mapper.getSerializationConfig().withFilters(filterProvider));
Note that usually it is better to use method
filteredWriter(org.codehaus.jackson.map.ser.FilterProvider)
; however, sometimes this method is more convenient. For example, some frameworks only allow configuring of ObjectMapper instances and not ObjectWriters.- Since:
- 1.8
-
getJsonFactory
Method that can be used to get hold ofJsonFactory
that this mapper uses if it needs to constructJsonParser
s and/orJsonGenerator
s.- Returns:
JsonFactory
that this mapper uses when it needs to construct Json parser and generators
-
setDateFormat
Method for configuring the defaultDateFormat
to use when serializing time values as Strings, and deserializing from JSON Strings. This is preferably to directly modifyingSerializationConfig
andDeserializationConfig
instances. If you need per-request configuration, usewriter(DateFormat)
to create properly configuredObjectWriter
and use that; this becauseObjectWriter
s are thread-safe whereas ObjectMapper itself is only thread-safe when configuring methods (such as this one) are NOT called.- Since:
- 1.8
-
setHandlerInstantiator
Method for configuringHandlerInstantiator
to use for creating instances of handlers (such as serializers, deserializers, type and type id resolvers), given a class.- Parameters:
hi
- Instantiator to use; if null, use the default implementation
-
setInjectableValues
- Since:
- 1.9
-
configure
Method for changing state of an on/off serialization feature for this object mapper.This is method is basically a shortcut method for calling
SerializationConfig.set(org.codehaus.jackson.map.SerializationConfig.Feature, boolean)
on the sharedSerializationConfig
object with given arguments. -
configure
Method for changing state of an on/off deserialization feature for this object mapper.This is method is basically a shortcut method for calling
DeserializationConfig.set(org.codehaus.jackson.map.DeserializationConfig.Feature, boolean)
on the sharedDeserializationConfig
object with given arguments. -
configure
Method for changing state of an on/offJsonParser
feature forJsonFactory
instance this object mapper uses.This is method is basically a shortcut method for calling
JsonFactory.setParserFeature(org.codehaus.jackson.JsonParser.Feature, boolean)
on the sharedJsonFactory
this mapper uses (which is accessible usinggetJsonFactory()
).- Since:
- 1.2
-
configure
Method for changing state of an on/offJsonGenerator
feature forJsonFactory
instance this object mapper uses.This is method is basically a shortcut method for calling
JsonFactory.setGeneratorFeature(org.codehaus.jackson.JsonGenerator.Feature, boolean)
on the sharedJsonFactory
this mapper uses (which is accessible usinggetJsonFactory()
).- Since:
- 1.2
-
enable
Method for enabling specifiedDeserializationConfig
features. Modifies and returns this instance; no new object is created.- Since:
- 1.9
-
disable
Method for enabling specifiedDeserializationConfig
features. Modifies and returns this instance; no new object is created.- Since:
- 1.9
-
enable
Method for enabling specifiedDeserializationConfig
features. Modifies and returns this instance; no new object is created.- Since:
- 1.9
-
disable
Method for enabling specifiedDeserializationConfig
features. Modifies and returns this instance; no new object is created.- Since:
- 1.9
-
isEnabled
Convenience method, equivalent to:getSerializationConfig().isEnabled(f);
- Since:
- 1.9
-
isEnabled
Convenience method, equivalent to:getDeserializationConfig().isEnabled(f);
- Since:
- 1.9
-
isEnabled
Convenience method, equivalent to:getJsonFactory().isEnabled(f);
- Since:
- 1.9
-
isEnabled
Convenience method, equivalent to:getJsonFactory().isEnabled(f);
- Since:
- 1.9
-
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()
- Since:
- 1.2
-
readValue
public <T> T readValue(JsonParser jp, Class<T> valueType) throws IOException, JsonParseException, JsonMappingException 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 can not be introspected when using this method.- Specified by:
readValue
in classObjectCodec
- Throws:
IOException
JsonParseException
JsonMappingException
-
readValue
public <T> T readValue(JsonParser jp, TypeReference<?> valueTypeRef) throws IOException, JsonParseException, JsonMappingException 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.- Specified by:
readValue
in classObjectCodec
- Throws:
IOException
JsonParseException
JsonMappingException
-
readValue
public <T> T readValue(JsonParser jp, JavaType valueType) throws IOException, JsonParseException, JsonMappingException 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
.- Specified by:
readValue
in classObjectCodec
- Throws:
IOException
JsonParseException
JsonMappingException
-
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).- Specified by:
readTree
in classObjectCodec
- Throws:
IOException
JsonProcessingException
-
readValues
public <T> MappingIterator<T> readValues(JsonParser jp, JavaType valueType) throws IOException, JsonProcessingException Method for reading sequence of Objects from parser stream.Note that
ObjectReader
has more complete set of variants.- Specified by:
readValues
in classObjectCodec
- Throws:
IOException
JsonProcessingException
- Since:
- 1.8
-
readValues
public <T> MappingIterator<T> readValues(JsonParser jp, Class<T> valueType) throws IOException, JsonProcessingException Method for reading sequence of Objects from parser stream.- Specified by:
readValues
in classObjectCodec
- Throws:
IOException
JsonProcessingException
- Since:
- 1.8
-
readValues
public <T> MappingIterator<T> readValues(JsonParser jp, TypeReference<?> valueTypeRef) throws IOException, JsonProcessingException Method for reading sequence of Objects from parser stream.- Specified by:
readValues
in classObjectCodec
- Throws:
IOException
JsonProcessingException
- Since:
- 1.8
-
readValue
public <T> T readValue(JsonParser jp, Class<T> valueType, DeserializationConfig cfg) throws IOException, JsonParseException, JsonMappingException 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 can not be introspected when using this method.- Parameters:
cfg
- Specific deserialization configuration to use for this operation. Note that not all config settings can be changed on per-operation basis: some changeds only take effect before calling the operation for the first time (for the mapper instance)- Throws:
IOException
JsonParseException
JsonMappingException
- Since:
- 1.1
-
readValue
public <T> T readValue(JsonParser jp, TypeReference<?> valueTypeRef, DeserializationConfig cfg) throws IOException, JsonParseException, JsonMappingException 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.- Parameters:
cfg
- Specific deserialization configuration to use for this operation. Note that not all config settings can be changed on per-operation basis: some changeds only take effect before calling the operation for the first time (for the mapper instance)- Throws:
IOException
JsonParseException
JsonMappingException
- Since:
- 1.1
-
readValue
public <T> T readValue(JsonParser jp, JavaType valueType, DeserializationConfig cfg) throws IOException, JsonParseException, JsonMappingException 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
.- Parameters:
cfg
- Specific deserialization configuration to use for this operation. Note that not all config settings can be changed on per-operation basis: some changeds only take effect before calling the operation for the first time (for the mapper instance)- Throws:
IOException
JsonParseException
JsonMappingException
- Since:
- 1.1
-
readTree
public JsonNode readTree(JsonParser jp, DeserializationConfig cfg) throws IOException, JsonProcessingException 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).- Parameters:
cfg
- Specific deserialization configuration to use for this operation. Note that not all config settings can be changed on per-operation basis: some changeds only take effect before calling the operation for the first time (for the mapper instance)- Throws:
IOException
JsonProcessingException
- Since:
- 1.1
-
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).- Parameters:
in
- Input stream used to read JSON content for building the JSON tree.- Throws:
IOException
JsonProcessingException
- Since:
- 1.3
-
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).- Parameters:
r
- Reader used to read JSON content for building the JSON tree.- Throws:
IOException
JsonProcessingException
- Since:
- 1.3
-
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).- Parameters:
content
- JSON content to parse to build the JSON tree.- Throws:
IOException
JsonProcessingException
- Since:
- 1.3
-
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).- Parameters:
content
- JSON content to parse to build the JSON tree.- Throws:
IOException
JsonProcessingException
- Since:
- 1.9
-
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).- Parameters:
file
- File of which contents to parse as JSON for building a tree instance- Throws:
IOException
JsonProcessingException
- Since:
- 1.9
-
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).- Parameters:
source
- URL to use for fetching contents to parse as JSON for building a tree instance- Throws:
IOException
JsonProcessingException
- Since:
- 1.9
-
writeValue
public void writeValue(JsonGenerator jgen, Object value) throws IOException, JsonGenerationException, JsonMappingException Method that can be used to serialize any Java value as JSON output, using providedJsonGenerator
.- Specified by:
writeValue
in classObjectCodec
- Throws:
IOException
JsonGenerationException
JsonMappingException
-
writeValue
public void writeValue(JsonGenerator jgen, Object value, SerializationConfig config) throws IOException, JsonGenerationException, JsonMappingException Method that can be used to serialize any Java value as JSON output, using providedJsonGenerator
, configured as per passed configuration object.- Throws:
IOException
JsonGenerationException
JsonMappingException
- Since:
- 1.1
-
writeTree
public void writeTree(JsonGenerator jgen, JsonNode rootNode) throws IOException, JsonProcessingException Method to serialize given JSON Tree, using generator provided.- Specified by:
writeTree
in classObjectCodec
- Throws:
IOException
JsonProcessingException
-
writeTree
public void writeTree(JsonGenerator jgen, JsonNode rootNode, SerializationConfig cfg) throws IOException, JsonProcessingException Method to serialize given Json Tree, using generator provided.- Throws:
IOException
JsonProcessingException
- Since:
- 1.1
-
createObjectNode
Note: return type is co-variant, as basic ObjectCodec abstraction can not refer to concrete node types (as it's part of core package, whereas impls are part of mapper package)
- Specified by:
createObjectNode
in classObjectCodec
- Since:
- 1.2
-
createArrayNode
Note: return type is co-variant, as basic ObjectCodec abstraction can not refer to concrete node types (as it's part of core package, whereas impls are part of mapper package)
- Specified by:
createArrayNode
in classObjectCodec
- Since:
- 1.2
-
treeAsTokens
Method for constructing aJsonParser
out of JSON tree representation.- Specified by:
treeAsTokens
in classObjectCodec
- Parameters:
n
- Root node of the tree that resulting parser will read from- Since:
- 1.3
-
treeToValue
public <T> T treeToValue(JsonNode n, Class<T> valueType) throws IOException, JsonParseException, JsonMappingException Convenience conversion method that will bind data given JSON tree contains into specific value (usually bean) type.Equivalent to:
objectMapper.convertValue(n, valueClass);
- Specified by:
treeToValue
in classObjectCodec
- Throws:
IOException
JsonParseException
JsonMappingException
-
valueToTree
Reverse oftreeToValue(org.codehaus.jackson.JsonNode, java.lang.Class<T>)
; given a value (usually bean), will construct equivalent JSON Tree representation. Functionally same as if serializing value into JSON and parsing JSON as tree, but more efficient.- Type Parameters:
T
- Actual node type; usually either basicJsonNode
orObjectNode
- Parameters:
fromValue
- Bean value to convert- Returns:
- Root node of the resulting JSON tree
- Throws:
IllegalArgumentException
- Since:
- 1.6
-
canSerialize
Method that can be called to check whether mapper thinks it could serialize an instance of given Class. Check is done by checking whether a serializer can be found for the type.- Returns:
- True if mapper can find a serializer for instances of given class (potentially serializable), false otherwise (not serializable)
-
canDeserialize
Method that can be called to check whether mapper thinks it could deserialize an Object of given type. Check is done by checking whether a deserializer can be found for the type.- Returns:
- True if mapper can find a serializer for instances of given class (potentially serializable), false otherwise (not serializable)
-
readValue
public <T> T readValue(File src, Class<T> valueType) throws IOException, JsonParseException, JsonMappingException -
readValue
public <T> T readValue(File src, TypeReference valueTypeRef) throws IOException, JsonParseException, JsonMappingException -
readValue
public <T> T readValue(File src, JavaType valueType) throws IOException, JsonParseException, JsonMappingException -
readValue
public <T> T readValue(URL src, Class<T> valueType) throws IOException, JsonParseException, JsonMappingException -
readValue
public <T> T readValue(URL src, TypeReference valueTypeRef) throws IOException, JsonParseException, JsonMappingException -
readValue
public <T> T readValue(URL src, JavaType valueType) throws IOException, JsonParseException, JsonMappingException -
readValue
public <T> T readValue(String content, Class<T> valueType) throws IOException, JsonParseException, JsonMappingException -
readValue
public <T> T readValue(String content, TypeReference valueTypeRef) throws IOException, JsonParseException, JsonMappingException -
readValue
public <T> T readValue(String content, JavaType valueType) throws IOException, JsonParseException, JsonMappingException -
readValue
public <T> T readValue(Reader src, Class<T> valueType) throws IOException, JsonParseException, JsonMappingException -
readValue
public <T> T readValue(Reader src, TypeReference valueTypeRef) throws IOException, JsonParseException, JsonMappingException -
readValue
public <T> T readValue(Reader src, JavaType valueType) throws IOException, JsonParseException, JsonMappingException -
readValue
public <T> T readValue(InputStream src, Class<T> valueType) throws IOException, JsonParseException, JsonMappingException -
readValue
public <T> T readValue(InputStream src, TypeReference valueTypeRef) throws IOException, JsonParseException, JsonMappingException -
readValue
public <T> T readValue(InputStream src, JavaType valueType) throws IOException, JsonParseException, JsonMappingException -
readValue
public <T> T readValue(byte[] src, Class<T> valueType) throws IOException, JsonParseException, JsonMappingException - Throws:
IOException
JsonParseException
JsonMappingException
- Since:
- 1.8
-
readValue
public <T> T readValue(byte[] src, int offset, int len, Class<T> valueType) throws IOException, JsonParseException, JsonMappingException -
readValue
public <T> T readValue(byte[] src, TypeReference valueTypeRef) throws IOException, JsonParseException, JsonMappingException - Throws:
IOException
JsonParseException
JsonMappingException
- Since:
- 1.8
-
readValue
public <T> T readValue(byte[] src, int offset, int len, TypeReference valueTypeRef) throws IOException, JsonParseException, JsonMappingException -
readValue
public <T> T readValue(byte[] src, JavaType valueType) throws IOException, JsonParseException, JsonMappingException - Throws:
IOException
JsonParseException
JsonMappingException
- Since:
- 1.8
-
readValue
public <T> T readValue(byte[] src, int offset, int len, JavaType valueType) throws IOException, JsonParseException, JsonMappingException -
readValue
public <T> T readValue(JsonNode root, Class<T> valueType) throws IOException, JsonParseException, JsonMappingException Convenience method for converting results from given JSON tree into given value type. Basically short-cut for:mapper.readValue(mapper.treeAsTokens(root), valueType);
- Throws:
IOException
JsonParseException
JsonMappingException
- Since:
- 1.6
-
readValue
public <T> T readValue(JsonNode root, TypeReference valueTypeRef) throws IOException, JsonParseException, JsonMappingException Convenience method for converting results from given JSON tree into given value type. Basically short-cut for:mapper.readValue(mapper.treeAsTokens(root), valueType);
- Throws:
IOException
JsonParseException
JsonMappingException
- Since:
- 1.6
-
readValue
public <T> T readValue(JsonNode root, JavaType valueType) throws IOException, JsonParseException, JsonMappingException Convenience method for converting results from given JSON tree into given value type. Basically short-cut for:mapper.readValue(mapper.treeAsTokens(root), valueType);
- Throws:
IOException
JsonParseException
JsonMappingException
- Since:
- 1.6
-
writeValue
public void writeValue(File resultFile, Object value) throws IOException, JsonGenerationException, JsonMappingException Method that can be used to serialize any Java value as JSON output, written to File provided. -
writeValue
public void writeValue(OutputStream out, Object value) throws IOException, JsonGenerationException, JsonMappingException 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,
JsonFactory
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). -
writeValue
public void writeValue(Writer w, Object value) throws IOException, JsonGenerationException, JsonMappingException 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,
JsonFactory
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). -
writeValueAsString
public String writeValueAsString(Object value) throws IOException, JsonGenerationException, JsonMappingException 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:
IOException
JsonGenerationException
JsonMappingException
- Since:
- 1.3
-
writeValueAsBytes
public byte[] writeValueAsBytes(Object value) throws IOException, JsonGenerationException, JsonMappingException 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:
IOException
JsonGenerationException
JsonMappingException
- Since:
- 1.5
-
writer
Convenience method for constructingObjectWriter
with default settings.- Since:
- 1.6
-
writer
Factory method for constructingObjectWriter
that will serialize objects using specifiedDateFormat
; or, if null passed, using timestamp (64-bit number.- Since:
- 1.9
-
writerWithView
Factory method for constructingObjectWriter
that will serialize objects using specified JSON View (filter).- Since:
- 1.9
-
writerWithType
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.- Since:
- 1.9
-
writerWithType
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.- Since:
- 1.9
-
writerWithType
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.- Since:
- 1.9
-
writer
Factory method for constructingObjectWriter
that will serialize objects using specified pretty printer for indentation (or if null, no pretty printer)- Since:
- 1.9
-
writerWithDefaultPrettyPrinter
Factory method for constructingObjectWriter
that will serialize objects using the default pretty printer for indentation- Since:
- 1.9
-
writer
Factory method for constructingObjectWriter
that will serialize objects using specified filter provider.- Since:
- 1.9
-
writer
Factory method for constructingObjectWriter
that will pass specific schema object toJsonGenerator
used for writing content.- Parameters:
schema
- Schema to pass to generator- Since:
- 1.9
-
typedWriter
Deprecated.Since 1.9, usewriterWithType(Class)
instead. -
typedWriter
Deprecated.Since 1.9, usewriterWithType(JavaType)
instead. -
typedWriter
Deprecated.Since 1.9, usewriterWithType(TypeReference)
instead. -
viewWriter
Deprecated.Since 1.9, usewriterWithView(Class)
instead. -
prettyPrintingWriter
Deprecated.Since 1.9, usewriter(FilterProvider)
instead. -
defaultPrettyPrintingWriter
Deprecated.Since 1.9, usewriterWithDefaultPrettyPrinter()
instead. -
filteredWriter
Deprecated.Since 1.9, usewriter(FilterProvider)
instead. -
schemaBasedWriter
Deprecated.Since 1.9, usewriter(FilterProvider)
instead. -
reader
Factory method for constructingObjectReader
with default settings. Note that the resulting instance is NOT usable as is, without defining expected value type.- Since:
- 1.6
-
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
- Since:
- 1.9
-
reader
Factory method for constructingObjectReader
that will read or update instances of specified type- Since:
- 1.6
-
reader
Factory method for constructingObjectReader
that will read or update instances of specified type- Since:
- 1.6
-
reader
Factory method for constructingObjectReader
that will read or update instances of specified type- Since:
- 1.6
-
reader
Factory method for constructingObjectReader
that will use specifiedJsonNodeFactory
for constructing JSON trees.- Since:
- 1.6
-
reader
Factory method for constructingObjectReader
that will pass specific schema object toJsonParser
used for reading content.- Parameters:
schema
- Schema to pass to parser- Since:
- 1.8
-
reader
Factory method for constructingObjectReader
that will use specified injectable values.- Parameters:
injectableValues
- Injectable values to use- Since:
- 1.9
-
updatingReader
Deprecated.Since 1.9, usereaderForUpdating(java.lang.Object)
instead. -
schemaBasedReader
Deprecated.Since 1.9, usereader(FormatSchema)
instead. -
convertValue
Convenience method for doing two-step conversion from given value, into instance of given value type. This is functionality equivalent to first serializing given value into JSON, then binding JSON data into value of given type, but may be executed without fully serializing into JSON. Same converters (serializers, deserializers) will be used as for data binding, meaning same object mapper configuration works.- 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 toValueTypeRef) throws IllegalArgumentException - Throws:
IllegalArgumentException
-
convertValue
- Throws:
IllegalArgumentException
-
_convert
- Throws:
IllegalArgumentException
-
generateJsonSchema
Generate Json-schema instance for specified class.- Parameters:
t
- The class to generate schema for- Returns:
- Constructed JSON schema.
- Throws:
JsonMappingException
-
generateJsonSchema
public JsonSchema generateJsonSchema(Class<?> t, SerializationConfig cfg) throws JsonMappingException Generate Json-schema instance for specified class, using specific serialization configuration- Parameters:
t
- The class to generate schema for- Returns:
- Constructed JSON schema.
- Throws:
JsonMappingException
-
_defaultPrettyPrinter
Helper method that should return default pretty-printer to use for generators constructed by this mapper, when instructed to use default pretty printer.- Since:
- 1.7
-
_configAndWriteValue
protected final void _configAndWriteValue(JsonGenerator jgen, Object value) throws IOException, JsonGenerationException, JsonMappingException Method called to configure the generator as necessary and then call write functionality -
_configAndWriteValue
protected final void _configAndWriteValue(JsonGenerator jgen, Object value, Class<?> viewClass) throws IOException, JsonGenerationException, JsonMappingException -
_readValue
protected Object _readValue(DeserializationConfig cfg, JsonParser jp, JavaType valueType) throws IOException, JsonParseException, JsonMappingException Actual implementation of value reading+binding operation. -
_readMapAndClose
protected Object _readMapAndClose(JsonParser jp, JavaType valueType) throws IOException, JsonParseException, JsonMappingException -
_initForReading
protected JsonToken _initForReading(JsonParser jp) throws IOException, JsonParseException, JsonMappingException 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 can not provide more tokens.
- Throws:
IOException
- if the underlying input source has problems during parsingJsonParseException
- if parser has problems parsing contentJsonMappingException
- if the parser does not have any more content to map (note: Json "null" value is considered content; enf-of-stream not)
-
_unwrapAndDeserialize
protected Object _unwrapAndDeserialize(JsonParser jp, JavaType rootType, DeserializationContext ctxt, JsonDeserializer<Object> deser) throws IOException, JsonParseException, JsonMappingException -
_findRootDeserializer
protected JsonDeserializer<Object> _findRootDeserializer(DeserializationConfig cfg, JavaType valueType) throws JsonMappingException Method called to locate deserializer for the passed root-level value.- Throws:
JsonMappingException
-
_createDeserializationContext
protected DeserializationContext _createDeserializationContext(JsonParser jp, DeserializationConfig cfg)
-
setSerializerFactory(org.codehaus.jackson.map.SerializerFactory)