Class ObjectMapper
- java.lang.Object
-
- org.codehaus.jackson.ObjectCodec
-
- org.codehaus.jackson.map.ObjectMapper
-
- All Implemented Interfaces:
Versioned
public class ObjectMapper extends ObjectCodec implements Versioned
This mapper (or, data binder, or codec) provides functionality for converting between Java objects (instances of JDK provided core classes, beans), and matching JSON constructs. It will use instances ofJsonParserandJsonGeneratorfor 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 Classes Modifier and Type Class Description static classObjectMapper.DefaultTypeResolverBuilderCustomizedTypeResolverBuilderthat provides type resolver builders used with so-called "default typing" (seeenableDefaultTyping()for details).static classObjectMapper.DefaultTypingEnumeration used withenableDefaultTyping()to specify what kind of types (classes) default typing should be used for.
-
Field Summary
Fields Modifier and Type Field Description protected DeserializationConfig_deserializationConfigConfiguration object that defines basic global settings for the serialization processprotected DeserializerProvider_deserializerProviderObject that manages access to deserializers used for deserializing JSON content into Java objects, including possible caching of the deserializers.protected InjectableValues_injectableValuesProvider for values to inject in deserialized POJOs.protected JsonFactory_jsonFactoryFactory used to createJsonParserandJsonGeneratorinstances as necessary.protected java.util.concurrent.ConcurrentHashMap<JavaType,JsonDeserializer<java.lang.Object>>_rootDeserializersWe will use a separate main-level Map for keeping track of root-level deserializers.protected SerializationConfig_serializationConfigConfiguration object that defines basic global settings for the serialization processprotected SerializerFactory_serializerFactorySerializer factory used for constructing serializers.protected SerializerProvider_serializerProviderObject that manages access to serializers used for serialization, including caching.protected SubtypeResolver_subtypeResolverRegistered concrete subtypes that can be used instead of (or in addition to) ones declared using annotations.protected TypeFactory_typeFactorySpecific factory used for creatingJavaTypeinstances; needed to allow modules to add more custom type handling (mostly to support types of non-Java JVM languages)protected static AnnotationIntrospectorDEFAULT_ANNOTATION_INTROSPECTORprotected static ClassIntrospector<? extends BeanDescription>DEFAULT_INTROSPECTORprotected static VisibilityChecker<?>STD_VISIBILITY_CHECKER
-
Constructor Summary
Constructors Constructor Description ObjectMapper()Default constructor, which will construct the defaultJsonFactoryas necessary, useStdSerializerProvideras itsSerializerProvider, andBeanSerializerFactoryas itsSerializerFactory.ObjectMapper(JsonFactory jf)Construct mapper that uses specifiedJsonFactoryfor constructing necessaryJsonParsers and/orJsonGenerators.ObjectMapper(JsonFactory jf, SerializerProvider sp, DeserializerProvider dp)ObjectMapper(JsonFactory jf, SerializerProvider sp, DeserializerProvider dp, SerializationConfig sconfig, DeserializationConfig dconfig)ObjectMapper(SerializerFactory sf)Deprecated.Use other constructors instead; note that you can just set serializer factory withsetSerializerFactory(org.codehaus.jackson.map.SerializerFactory)
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected void_configAndWriteValue(JsonGenerator jgen, java.lang.Object value)Method called to configure the generator as necessary and then call write functionalityprotected void_configAndWriteValue(JsonGenerator jgen, java.lang.Object value, java.lang.Class<?> viewClass)protected java.lang.Object_convert(java.lang.Object fromValue, JavaType toValueType)protected DeserializationContext_createDeserializationContext(JsonParser jp, DeserializationConfig cfg)protected PrettyPrinter_defaultPrettyPrinter()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<java.lang.Object>_findRootDeserializer(DeserializationConfig cfg, JavaType valueType)Method called to locate deserializer for the passed root-level value.protected JsonToken_initForReading(JsonParser jp)Method called to ensure that given parser is ready for reading content for data binding.protected java.lang.Object_readMapAndClose(JsonParser jp, JavaType valueType)protected java.lang.Object_readValue(DeserializationConfig cfg, JsonParser jp, JavaType valueType)Actual implementation of value reading+binding operation.protected java.lang.Object_unwrapAndDeserialize(JsonParser jp, JavaType rootType, DeserializationContext ctxt, JsonDeserializer<java.lang.Object> deser)booleancanDeserialize(JavaType type)Method that can be called to check whether mapper thinks it could deserialize an Object of given type.booleancanSerialize(java.lang.Class<?> type)Method that can be called to check whether mapper thinks it could serialize an instance of given Class.ObjectMapperconfigure(JsonGenerator.Feature f, boolean state)Method for changing state of an on/offJsonGeneratorfeature forJsonFactoryinstance this object mapper uses.ObjectMapperconfigure(JsonParser.Feature f, boolean state)Method for changing state of an on/offJsonParserfeature forJsonFactoryinstance this object mapper uses.ObjectMapperconfigure(DeserializationConfig.Feature f, boolean state)Method for changing state of an on/off deserialization feature for this object mapper.ObjectMapperconfigure(SerializationConfig.Feature f, boolean state)Method for changing state of an on/off serialization feature for this object mapper.JavaTypeconstructType(java.lang.reflect.Type t)Convenience method for constructingJavaTypeout of given type (typicallyjava.lang.Class), but without explicit context.<T> TconvertValue(java.lang.Object fromValue, java.lang.Class<T> toValueType)Convenience method for doing two-step conversion from given value, into instance of given value type.<T> TconvertValue(java.lang.Object fromValue, JavaType toValueType)<T> TconvertValue(java.lang.Object fromValue, TypeReference toValueTypeRef)DeserializationConfigcopyDeserializationConfig()Method that creates a copy of the shared defaultDeserializationConfigobject that defines configuration settings for deserialization.SerializationConfigcopySerializationConfig()Method that creates a copy of the shared defaultSerializationConfigobject that defines configuration settings for serialization.ArrayNodecreateArrayNode()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)ObjectNodecreateObjectNode()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)ObjectWriterdefaultPrettyPrintingWriter()Deprecated.Since 1.9, usewriterWithDefaultPrettyPrinter()instead.ObjectMapperdisable(DeserializationConfig.Feature... f)Method for enabling specifiedDeserializationConfigfeatures.ObjectMapperdisable(SerializationConfig.Feature... f)Method for enabling specifiedDeserializationConfigfeatures.ObjectMapperdisableDefaultTyping()Method for disabling automatic inclusion of type information; if so, only explicitly annotated types (ones withJsonTypeInfo) will have additional embedded type information.ObjectMapperenable(DeserializationConfig.Feature... f)Method for enabling specifiedDeserializationConfigfeatures.ObjectMapperenable(SerializationConfig.Feature... f)Method for enabling specifiedDeserializationConfigfeatures.ObjectMapperenableDefaultTyping()Convenience method that is equivalent to callingObjectMapperenableDefaultTyping(ObjectMapper.DefaultTyping dti)Convenience method that is equivalent to callingObjectMapperenableDefaultTyping(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).ObjectMapperenableDefaultTypingAsProperty(ObjectMapper.DefaultTyping applicability, java.lang.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)ObjectWriterfilteredWriter(FilterProvider filterProvider)Deprecated.Since 1.9, usewriter(FilterProvider)instead.JsonSchemagenerateJsonSchema(java.lang.Class<?> t)Generate Json-schema instance for specified class.JsonSchemagenerateJsonSchema(java.lang.Class<?> t, SerializationConfig cfg)Generate Json-schema instance for specified class, using specific serialization configurationDeserializationConfiggetDeserializationConfig()Method that returns the shared defaultDeserializationConfigobject that defines configuration settings for deserialization.DeserializerProvidergetDeserializerProvider()JsonFactorygetJsonFactory()Method that can be used to get hold ofJsonFactorythat this mapper uses if it needs to constructJsonParsers and/orJsonGenerators.JsonNodeFactorygetNodeFactory()Method that can be used to get hold ofJsonNodeFactorythat this mapper will use when directly constructing rootJsonNodeinstances for Trees.SerializationConfiggetSerializationConfig()Method that returns the shared defaultSerializationConfigobject that defines configuration settings for serialization.SerializerProvidergetSerializerProvider()SubtypeResolvergetSubtypeResolver()Method for accessing subtype resolver in use.TypeFactorygetTypeFactory()Accessor for getting currently configuredTypeFactoryinstance.VisibilityChecker<?>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.booleanisEnabled(JsonGenerator.Feature f)Convenience method, equivalent to:booleanisEnabled(JsonParser.Feature f)Convenience method, equivalent to:booleanisEnabled(DeserializationConfig.Feature f)Convenience method, equivalent to:booleanisEnabled(SerializationConfig.Feature f)Convenience method, equivalent to:ObjectWriterprettyPrintingWriter(PrettyPrinter pp)Deprecated.Since 1.9, usewriter(FilterProvider)instead.ObjectReaderreader()Factory method for constructingObjectReaderwith default settings.ObjectReaderreader(java.lang.Class<?> type)Factory method for constructingObjectReaderthat will read or update instances of specified typeObjectReaderreader(FormatSchema schema)Factory method for constructingObjectReaderthat will pass specific schema object toJsonParserused for reading content.ObjectReaderreader(InjectableValues injectableValues)Factory method for constructingObjectReaderthat will use specified injectable values.ObjectReaderreader(JsonNodeFactory f)Factory method for constructingObjectReaderthat will use specifiedJsonNodeFactoryfor constructing JSON trees.ObjectReaderreader(JavaType type)Factory method for constructingObjectReaderthat will read or update instances of specified typeObjectReaderreader(TypeReference<?> type)Factory method for constructingObjectReaderthat will read or update instances of specified typeObjectReaderreaderForUpdating(java.lang.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.JsonNodereadTree(byte[] content)Method to deserialize JSON content as tree expressed using set ofJsonNodeinstances.JsonNodereadTree(java.io.File file)Method to deserialize JSON content as tree expressed using set ofJsonNodeinstances.JsonNodereadTree(java.io.InputStream in)Method to deserialize JSON content as tree expressed using set ofJsonNodeinstances.JsonNodereadTree(java.io.Reader r)Method to deserialize JSON content as tree expressed using set ofJsonNodeinstances.JsonNodereadTree(java.lang.String content)Method to deserialize JSON content as tree expressed using set ofJsonNodeinstances.JsonNodereadTree(java.net.URL source)Method to deserialize JSON content as tree expressed using set ofJsonNodeinstances.JsonNodereadTree(JsonParser jp)Method to deserialize JSON content as tree expressed using set ofJsonNodeinstances.JsonNodereadTree(JsonParser jp, DeserializationConfig cfg)Method to deserialize JSON content as tree expressed using set ofJsonNodeinstances.<T> TreadValue(byte[] src, int offset, int len, java.lang.Class<T> valueType)<T> TreadValue(byte[] src, int offset, int len, JavaType valueType)<T> TreadValue(byte[] src, int offset, int len, TypeReference valueTypeRef)<T> TreadValue(byte[] src, java.lang.Class<T> valueType)<T> TreadValue(byte[] src, JavaType valueType)<T> TreadValue(byte[] src, TypeReference valueTypeRef)<T> TreadValue(java.io.File src, java.lang.Class<T> valueType)<T> TreadValue(java.io.File src, JavaType valueType)<T> TreadValue(java.io.File src, TypeReference valueTypeRef)<T> TreadValue(java.io.InputStream src, java.lang.Class<T> valueType)<T> TreadValue(java.io.InputStream src, JavaType valueType)<T> TreadValue(java.io.InputStream src, TypeReference valueTypeRef)<T> TreadValue(java.io.Reader src, java.lang.Class<T> valueType)<T> TreadValue(java.io.Reader src, JavaType valueType)<T> TreadValue(java.io.Reader src, TypeReference valueTypeRef)<T> TreadValue(java.lang.String content, java.lang.Class<T> valueType)<T> TreadValue(java.lang.String content, JavaType valueType)<T> TreadValue(java.lang.String content, TypeReference valueTypeRef)<T> TreadValue(java.net.URL src, java.lang.Class<T> valueType)<T> TreadValue(java.net.URL src, JavaType valueType)<T> TreadValue(java.net.URL src, TypeReference valueTypeRef)<T> TreadValue(JsonNode root, java.lang.Class<T> valueType)Convenience method for converting results from given JSON tree into given value type.<T> TreadValue(JsonNode root, JavaType valueType)Convenience method for converting results from given JSON tree into given value type.<T> TreadValue(JsonNode root, TypeReference valueTypeRef)Convenience method for converting results from given JSON tree into given value type.<T> TreadValue(JsonParser jp, java.lang.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> TreadValue(JsonParser jp, java.lang.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> TreadValue(JsonParser jp, JavaType valueType)Method to deserialize JSON content into a Java type, reference to which is passed as argument.<T> TreadValue(JsonParser jp, JavaType valueType, DeserializationConfig cfg)Method to deserialize JSON content into a Java type, reference to which is passed as argument.<T> TreadValue(JsonParser jp, TypeReference<?> valueTypeRef)Method to deserialize JSON content into a Java type, reference to which is passed as argument.<T> TreadValue(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, java.lang.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.voidregisterModule(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.voidregisterSubtypes(java.lang.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).voidregisterSubtypes(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).ObjectReaderschemaBasedReader(FormatSchema schema)Deprecated.Since 1.9, usereader(FormatSchema)instead.ObjectWriterschemaBasedWriter(FormatSchema schema)Deprecated.Since 1.9, usewriter(FilterProvider)instead.ObjectMappersetAnnotationIntrospector(AnnotationIntrospector ai)Method for changingAnnotationIntrospectorused by this mapper instance for both serialization and deserializationvoidsetDateFormat(java.text.DateFormat dateFormat)Method for configuring the defaultDateFormatto use when serializing time values as Strings, and deserializing from JSON Strings.ObjectMappersetDefaultTyping(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.ObjectMappersetDeserializationConfig(DeserializationConfig cfg)Method for replacing the shared default deserialization configuration object.ObjectMappersetDeserializerProvider(DeserializerProvider p)Method for setting specificDeserializerProviderto use for handling caching ofJsonDeserializerinstances.voidsetFilters(FilterProvider filterProvider)Convenience method that is equivalent to:voidsetHandlerInstantiator(HandlerInstantiator hi)Method for configuringHandlerInstantiatorto use for creating instances of handlers (such as serializers, deserializers, type and type id resolvers), given a class.ObjectMappersetInjectableValues(InjectableValues injectableValues)ObjectMappersetNodeFactory(JsonNodeFactory f)Method for specifyingJsonNodeFactoryto use for constructing root level tree nodes (via methodcreateObjectNode()ObjectMappersetPropertyNamingStrategy(PropertyNamingStrategy s)Method for setting custom property naming strategy to use.ObjectMappersetSerializationConfig(SerializationConfig cfg)Method for replacing the shared default serialization configuration object.ObjectMappersetSerializationInclusion(JsonSerialize.Inclusion incl)Method for setting defalt POJO property inclusion strategy for serialization.ObjectMappersetSerializerFactory(SerializerFactory f)Method for setting specificSerializerFactoryto use for constructing (bean) serializers.ObjectMappersetSerializerProvider(SerializerProvider p)Method for setting specificSerializerProviderto use for handling caching ofJsonSerializerinstances.voidsetSubtypeResolver(SubtypeResolver r)Method for setting custom subtype resolver to use.ObjectMappersetTypeFactory(TypeFactory f)Method that can be used to overrideTypeFactoryinstance used by this mapper.ObjectMappersetVisibility(JsonMethod forMethod, JsonAutoDetect.Visibility visibility)Convenience method that allows changing configuration for underlyingVisibilityCheckers, to change details of what kinds of properties are auto-detected.voidsetVisibilityChecker(VisibilityChecker<?> vc)Method for setting currently configured visibility checker; object used for determining whether given property element (method, field, constructor) can be auto-detected or not.JsonParsertreeAsTokens(JsonNode n)Method for constructing aJsonParserout of JSON tree representation.<T> TtreeToValue(JsonNode n, java.lang.Class<T> valueType)Convenience conversion method that will bind data given JSON tree contains into specific value (usually bean) type.ObjectWritertypedWriter(java.lang.Class<?> rootType)Deprecated.Since 1.9, usewriterWithType(Class)instead.ObjectWritertypedWriter(JavaType rootType)Deprecated.Since 1.9, usewriterWithType(JavaType)instead.ObjectWritertypedWriter(TypeReference<?> rootType)Deprecated.Since 1.9, usewriterWithType(TypeReference)instead.ObjectReaderupdatingReader(java.lang.Object valueToUpdate)Deprecated.Since 1.9, usereaderForUpdating(java.lang.Object)instead.<T extends JsonNode>
TvalueToTree(java.lang.Object fromValue)Reverse oftreeToValue(org.codehaus.jackson.JsonNode, java.lang.Class<T>); given a value (usually bean), will construct equivalent JSON Tree representation.Versionversion()Method that will return version information stored in and read from jar that contains this class.ObjectWriterviewWriter(java.lang.Class<?> serializationView)Deprecated.Since 1.9, usewriterWithView(Class)instead.ObjectMapperwithModule(Module module)Fluent-style alternative toregisterModule(org.codehaus.jackson.map.Module); functionally equivalent to:ObjectWriterwriter()Convenience method for constructingObjectWriterwith default settings.ObjectWriterwriter(java.text.DateFormat df)Factory method for constructingObjectWriterthat will serialize objects using specifiedDateFormat; or, if null passed, using timestamp (64-bit number.ObjectWriterwriter(FormatSchema schema)Factory method for constructingObjectWriterthat will pass specific schema object toJsonGeneratorused for writing content.ObjectWriterwriter(FilterProvider filterProvider)Factory method for constructingObjectWriterthat will serialize objects using specified filter provider.ObjectWriterwriter(PrettyPrinter pp)Factory method for constructingObjectWriterthat will serialize objects using specified pretty printer for indentation (or if null, no pretty printer)ObjectWriterwriterWithDefaultPrettyPrinter()Factory method for constructingObjectWriterthat will serialize objects using the default pretty printer for indentationObjectWriterwriterWithType(java.lang.Class<?> rootType)Factory method for constructingObjectWriterthat will serialize objects using specified root type, instead of actual runtime type of value.ObjectWriterwriterWithType(JavaType rootType)Factory method for constructingObjectWriterthat will serialize objects using specified root type, instead of actual runtime type of value.ObjectWriterwriterWithType(TypeReference<?> rootType)Factory method for constructingObjectWriterthat will serialize objects using specified root type, instead of actual runtime type of value.ObjectWriterwriterWithView(java.lang.Class<?> serializationView)Factory method for constructingObjectWriterthat will serialize objects using specified JSON View (filter).voidwriteTree(JsonGenerator jgen, JsonNode rootNode)Method to serialize given JSON Tree, using generator provided.voidwriteTree(JsonGenerator jgen, JsonNode rootNode, SerializationConfig cfg)Method to serialize given Json Tree, using generator provided.voidwriteValue(java.io.File resultFile, java.lang.Object value)Method that can be used to serialize any Java value as JSON output, written to File provided.voidwriteValue(java.io.OutputStream out, java.lang.Object value)Method that can be used to serialize any Java value as JSON output, using output stream provided (using encodingJsonEncoding.UTF8).voidwriteValue(java.io.Writer w, java.lang.Object value)Method that can be used to serialize any Java value as JSON output, using Writer provided.voidwriteValue(JsonGenerator jgen, java.lang.Object value)Method that can be used to serialize any Java value as JSON output, using providedJsonGenerator.voidwriteValue(JsonGenerator jgen, java.lang.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(java.lang.Object value)Method that can be used to serialize any Java value as a byte array.java.lang.StringwriteValueAsString(java.lang.Object value)Method that can be used to serialize any Java value as a String.
-
-
-
Field Detail
-
DEFAULT_INTROSPECTOR
protected static final ClassIntrospector<? extends BeanDescription> DEFAULT_INTROSPECTOR
-
DEFAULT_ANNOTATION_INTROSPECTOR
protected static final AnnotationIntrospector DEFAULT_ANNOTATION_INTROSPECTOR
-
STD_VISIBILITY_CHECKER
protected static final VisibilityChecker<?> STD_VISIBILITY_CHECKER
- Since:
- 1.5
-
_jsonFactory
protected final JsonFactory _jsonFactory
Factory used to createJsonParserandJsonGeneratorinstances as necessary.
-
_subtypeResolver
protected SubtypeResolver _subtypeResolver
Registered concrete subtypes that can be used instead of (or in addition to) ones declared using annotations.- Since:
- 1.6
-
_typeFactory
protected TypeFactory _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
protected InjectableValues _injectableValues
Provider for values to inject in deserialized POJOs.- Since:
- 1.9
-
_serializationConfig
protected SerializationConfig _serializationConfig
Configuration object that defines basic global settings for the serialization process
-
_serializerProvider
protected SerializerProvider _serializerProvider
Object that manages access to serializers used for serialization, including caching. It is configured with_serializerFactoryto allow for constructing custom serializers.
-
_serializerFactory
protected SerializerFactory _serializerFactory
Serializer factory used for constructing serializers.
-
_deserializationConfig
protected DeserializationConfig _deserializationConfig
Configuration object that defines basic global settings for the serialization process
-
_deserializerProvider
protected DeserializerProvider _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 toDeserializerFactoryto use for constructing acutal deserializers.
-
_rootDeserializers
protected final java.util.concurrent.ConcurrentHashMap<JavaType,JsonDeserializer<java.lang.Object>> _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 Detail
-
ObjectMapper
public ObjectMapper()
Default constructor, which will construct the defaultJsonFactoryas necessary, useStdSerializerProvideras itsSerializerProvider, andBeanSerializerFactoryas 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
public ObjectMapper(JsonFactory jf)
Construct mapper that uses specifiedJsonFactoryfor constructing necessaryJsonParsers and/orJsonGenerators.
-
ObjectMapper
@Deprecated public ObjectMapper(SerializerFactory sf)
Deprecated.Use other constructors instead; note that you can just set serializer factory withsetSerializerFactory(org.codehaus.jackson.map.SerializerFactory)Construct mapper that uses specifiedSerializerFactoryfor constructing necessary serializers.
-
ObjectMapper
public ObjectMapper(JsonFactory jf, SerializerProvider sp, DeserializerProvider dp)
-
ObjectMapper
public ObjectMapper(JsonFactory jf, SerializerProvider sp, DeserializerProvider dp, SerializationConfig sconfig, DeserializationConfig dconfig)
- Parameters:
jf- JsonFactory to use: if null, a newMappingJsonFactorywill be constructedsp- SerializerProvider to use: if null, aStdSerializerProviderwill be constructeddp- DeserializerProvider to use: if null, aStdDeserializerProviderwill be constructedsconfig- Serialization configuration to use; if null, basicSerializationConfigwill be constructeddconfig- Deserialization configuration to use; if null, basicDeserializationConfigwill be constructed
-
-
Method Detail
-
version
public Version version()
Method that will return version information stored in and read from jar that contains this class.
-
registerModule
public 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.- Parameters:
module- Module to register- Since:
- 1.7
-
withModule
public ObjectMapper withModule(Module module)
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
public SerializationConfig getSerializationConfig()
Method that returns the shared defaultSerializationConfigobject 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
public SerializationConfig copySerializationConfig()
Method that creates a copy of the shared defaultSerializationConfigobject 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 separateSerializationConfigargument.The use case is that of changing object settings of the configuration (like date format being used, see
SerializationConfig.setDateFormat(java.text.DateFormat)).
-
setSerializationConfig
public ObjectMapper setSerializationConfig(SerializationConfig cfg)
Method for replacing the shared default serialization configuration object.
-
getDeserializationConfig
public DeserializationConfig getDeserializationConfig()
Method that returns the shared defaultDeserializationConfigobject 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
public DeserializationConfig copyDeserializationConfig()
Method that creates a copy of the shared defaultDeserializationConfigobject 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 separateDeserializationConfigargument.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
public ObjectMapper setDeserializationConfig(DeserializationConfig cfg)
Method for replacing the shared default deserialization configuration object.
-
setSerializerFactory
public ObjectMapper setSerializerFactory(SerializerFactory f)
Method for setting specificSerializerFactoryto use for constructing (bean) serializers.
-
setSerializerProvider
public ObjectMapper setSerializerProvider(SerializerProvider p)
Method for setting specificSerializerProviderto use for handling caching ofJsonSerializerinstances.
-
getSerializerProvider
public SerializerProvider getSerializerProvider()
- Since:
- 1.4
-
setDeserializerProvider
public ObjectMapper setDeserializerProvider(DeserializerProvider p)
Method for setting specificDeserializerProviderto use for handling caching ofJsonDeserializerinstances.
-
getDeserializerProvider
public DeserializerProvider getDeserializerProvider()
- Since:
- 1.4
-
getVisibilityChecker
public VisibilityChecker<?> 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
public void setVisibilityChecker(VisibilityChecker<?> vc)
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
public ObjectMapper setVisibility(JsonMethod forMethod, JsonAutoDetect.Visibility visibility)
Convenience method that allows changing configuration for underlyingVisibilityCheckers, 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
public SubtypeResolver getSubtypeResolver()
Method for accessing subtype resolver in use.- Since:
- 1.6
-
setSubtypeResolver
public void setSubtypeResolver(SubtypeResolver r)
Method for setting custom subtype resolver to use.- Since:
- 1.6
-
setAnnotationIntrospector
public ObjectMapper setAnnotationIntrospector(AnnotationIntrospector ai)
Method for changingAnnotationIntrospectorused by this mapper instance for both serialization and deserialization- Since:
- 1.8
-
setPropertyNamingStrategy
public ObjectMapper setPropertyNamingStrategy(PropertyNamingStrategy s)
Method for setting custom property naming strategy to use.- Since:
- 1.8
-
setSerializationInclusion
public ObjectMapper setSerializationInclusion(JsonSerialize.Inclusion incl)
Method for setting defalt POJO property inclusion strategy for serialization. Equivalent to:mapper.setSerializationConfig(mapper.getSerializationConfig().withSerializationInclusion(incl));
- Since:
- 1.9
-
enableDefaultTyping
public ObjectMapper enableDefaultTyping()
Convenience method that is equivalent to callingenableObjectTyping(DefaultTyping.OBJECT_AND_NON_CONCRETE);
-
enableDefaultTyping
public ObjectMapper enableDefaultTyping(ObjectMapper.DefaultTyping dti)
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.DefaultTypingfor more information.
-
enableDefaultTypingAsProperty
public ObjectMapper enableDefaultTypingAsProperty(ObjectMapper.DefaultTyping applicability, java.lang.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
public ObjectMapper disableDefaultTyping()
Method for disabling automatic inclusion of type information; if so, only explicitly annotated types (ones withJsonTypeInfo) will have additional embedded type information.
-
setDefaultTyping
public ObjectMapper 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.- Parameters:
typer- Type information inclusion handler
-
registerSubtypes
public void registerSubtypes(java.lang.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). Type for given class is determined from appropriate annotation; or if missing, default name (unqualified class name)- Since:
- 1.6
-
registerSubtypes
public 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). 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
public TypeFactory getTypeFactory()
Accessor for getting currently configuredTypeFactoryinstance.- Since:
- 1.8
-
setTypeFactory
public ObjectMapper setTypeFactory(TypeFactory f)
Method that can be used to overrideTypeFactoryinstance used by this mapper.Note: will also set
TypeFactorythat deserialization and serialization config objects use.
-
constructType
public JavaType constructType(java.lang.reflect.Type t)
Convenience method for constructingJavaTypeout of given type (typicallyjava.lang.Class), but without explicit context.- Since:
- 1.8
-
setNodeFactory
public ObjectMapper setNodeFactory(JsonNodeFactory f)
Method for specifyingJsonNodeFactoryto use for constructing root level tree nodes (via methodcreateObjectNode()- Since:
- 1.2
-
setFilters
public void setFilters(FilterProvider filterProvider)
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
public JsonFactory getJsonFactory()
Method that can be used to get hold ofJsonFactorythat this mapper uses if it needs to constructJsonParsers and/orJsonGenerators.- Returns:
JsonFactorythat this mapper uses when it needs to construct Json parser and generators
-
setDateFormat
public void setDateFormat(java.text.DateFormat dateFormat)
Method for configuring the defaultDateFormatto use when serializing time values as Strings, and deserializing from JSON Strings. This is preferably to directly modifyingSerializationConfigandDeserializationConfiginstances. If you need per-request configuration, usewriter(DateFormat)to create properly configuredObjectWriterand use that; this becauseObjectWriters are thread-safe whereas ObjectMapper itself is only thread-safe when configuring methods (such as this one) are NOT called.- Since:
- 1.8
-
setHandlerInstantiator
public void setHandlerInstantiator(HandlerInstantiator hi)
Method for configuringHandlerInstantiatorto 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
public ObjectMapper setInjectableValues(InjectableValues injectableValues)
- Since:
- 1.9
-
configure
public ObjectMapper configure(SerializationConfig.Feature f, boolean state)
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 sharedSerializationConfigobject with given arguments.
-
configure
public ObjectMapper configure(DeserializationConfig.Feature f, boolean state)
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 sharedDeserializationConfigobject with given arguments.
-
configure
public ObjectMapper configure(JsonParser.Feature f, boolean state)
Method for changing state of an on/offJsonParserfeature forJsonFactoryinstance this object mapper uses.This is method is basically a shortcut method for calling
JsonFactory.setParserFeature(org.codehaus.jackson.JsonParser.Feature, boolean)on the sharedJsonFactorythis mapper uses (which is accessible usinggetJsonFactory()).- Since:
- 1.2
-
configure
public ObjectMapper configure(JsonGenerator.Feature f, boolean state)
Method for changing state of an on/offJsonGeneratorfeature forJsonFactoryinstance this object mapper uses.This is method is basically a shortcut method for calling
JsonFactory.setGeneratorFeature(org.codehaus.jackson.JsonGenerator.Feature, boolean)on the sharedJsonFactorythis mapper uses (which is accessible usinggetJsonFactory()).- Since:
- 1.2
-
enable
public ObjectMapper enable(DeserializationConfig.Feature... f)
Method for enabling specifiedDeserializationConfigfeatures. Modifies and returns this instance; no new object is created.- Since:
- 1.9
-
disable
public ObjectMapper disable(DeserializationConfig.Feature... f)
Method for enabling specifiedDeserializationConfigfeatures. Modifies and returns this instance; no new object is created.- Since:
- 1.9
-
enable
public ObjectMapper enable(SerializationConfig.Feature... f)
Method for enabling specifiedDeserializationConfigfeatures. Modifies and returns this instance; no new object is created.- Since:
- 1.9
-
disable
public ObjectMapper disable(SerializationConfig.Feature... f)
Method for enabling specifiedDeserializationConfigfeatures. Modifies and returns this instance; no new object is created.- Since:
- 1.9
-
isEnabled
public boolean isEnabled(SerializationConfig.Feature f)
Convenience method, equivalent to:getSerializationConfig().isEnabled(f);
- Since:
- 1.9
-
isEnabled
public boolean isEnabled(DeserializationConfig.Feature f)
Convenience method, equivalent to:getDeserializationConfig().isEnabled(f);
- Since:
- 1.9
-
isEnabled
public boolean isEnabled(JsonParser.Feature f)
Convenience method, equivalent to:getJsonFactory().isEnabled(f);
- Since:
- 1.9
-
isEnabled
public boolean isEnabled(JsonGenerator.Feature f)
Convenience method, equivalent to:getJsonFactory().isEnabled(f);
- Since:
- 1.9
-
getNodeFactory
public JsonNodeFactory 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()
- Since:
- 1.2
-
readValue
public <T> T readValue(JsonParser jp, java.lang.Class<T> valueType) throws java.io.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 (
CollectionorMap. The reason is that due to type erasure, key and value types can not be introspected when using this method.- Specified by:
readValuein classObjectCodec- Throws:
java.io.IOExceptionJsonParseExceptionJsonMappingException
-
readValue
public <T> T readValue(JsonParser jp, TypeReference<?> valueTypeRef) throws java.io.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:
readValuein classObjectCodec- Throws:
java.io.IOExceptionJsonParseExceptionJsonMappingException
-
readValue
public <T> T readValue(JsonParser jp, JavaType valueType) throws java.io.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:
readValuein classObjectCodec- Throws:
java.io.IOExceptionJsonParseExceptionJsonMappingException
-
readTree
public JsonNode readTree(JsonParser jp) throws java.io.IOException, JsonProcessingException
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).- Specified by:
readTreein classObjectCodec- Throws:
java.io.IOExceptionJsonProcessingException
-
readValues
public <T> MappingIterator<T> readValues(JsonParser jp, JavaType valueType) throws java.io.IOException, JsonProcessingException
Method for reading sequence of Objects from parser stream.Note that
ObjectReaderhas more complete set of variants.- Specified by:
readValuesin classObjectCodec- Throws:
java.io.IOExceptionJsonProcessingException- Since:
- 1.8
-
readValues
public <T> MappingIterator<T> readValues(JsonParser jp, java.lang.Class<T> valueType) throws java.io.IOException, JsonProcessingException
Method for reading sequence of Objects from parser stream.- Specified by:
readValuesin classObjectCodec- Throws:
java.io.IOExceptionJsonProcessingException- Since:
- 1.8
-
readValues
public <T> MappingIterator<T> readValues(JsonParser jp, TypeReference<?> valueTypeRef) throws java.io.IOException, JsonProcessingException
Method for reading sequence of Objects from parser stream.- Specified by:
readValuesin classObjectCodec- Throws:
java.io.IOExceptionJsonProcessingException- Since:
- 1.8
-
readValue
public <T> T readValue(JsonParser jp, java.lang.Class<T> valueType, DeserializationConfig cfg) throws java.io.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 (
CollectionorMap. 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:
java.io.IOExceptionJsonParseExceptionJsonMappingException- Since:
- 1.1
-
readValue
public <T> T readValue(JsonParser jp, TypeReference<?> valueTypeRef, DeserializationConfig cfg) throws java.io.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:
java.io.IOExceptionJsonParseExceptionJsonMappingException- Since:
- 1.1
-
readValue
public <T> T readValue(JsonParser jp, JavaType valueType, DeserializationConfig cfg) throws java.io.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:
java.io.IOExceptionJsonParseExceptionJsonMappingException- Since:
- 1.1
-
readTree
public JsonNode readTree(JsonParser jp, DeserializationConfig cfg) throws java.io.IOException, JsonProcessingException
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).- 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:
java.io.IOExceptionJsonProcessingException- Since:
- 1.1
-
readTree
public JsonNode readTree(java.io.InputStream in) throws java.io.IOException, JsonProcessingException
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).- Parameters:
in- Input stream used to read JSON content for building the JSON tree.- Throws:
java.io.IOExceptionJsonProcessingException- Since:
- 1.3
-
readTree
public JsonNode readTree(java.io.Reader r) throws java.io.IOException, JsonProcessingException
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).- Parameters:
r- Reader used to read JSON content for building the JSON tree.- Throws:
java.io.IOExceptionJsonProcessingException- Since:
- 1.3
-
readTree
public JsonNode readTree(java.lang.String content) throws java.io.IOException, JsonProcessingException
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).- Parameters:
content- JSON content to parse to build the JSON tree.- Throws:
java.io.IOExceptionJsonProcessingException- Since:
- 1.3
-
readTree
public JsonNode readTree(byte[] content) throws java.io.IOException, JsonProcessingException
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).- Parameters:
content- JSON content to parse to build the JSON tree.- Throws:
java.io.IOExceptionJsonProcessingException- Since:
- 1.9
-
readTree
public JsonNode readTree(java.io.File file) throws java.io.IOException, JsonProcessingException
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).- Parameters:
file- File of which contents to parse as JSON for building a tree instance- Throws:
java.io.IOExceptionJsonProcessingException- Since:
- 1.9
-
readTree
public JsonNode readTree(java.net.URL source) throws java.io.IOException, JsonProcessingException
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).- Parameters:
source- URL to use for fetching contents to parse as JSON for building a tree instance- Throws:
java.io.IOExceptionJsonProcessingException- Since:
- 1.9
-
writeValue
public void writeValue(JsonGenerator jgen, java.lang.Object value) throws java.io.IOException, JsonGenerationException, JsonMappingException
Method that can be used to serialize any Java value as JSON output, using providedJsonGenerator.- Specified by:
writeValuein classObjectCodec- Throws:
java.io.IOExceptionJsonGenerationExceptionJsonMappingException
-
writeValue
public void writeValue(JsonGenerator jgen, java.lang.Object value, SerializationConfig config) throws java.io.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:
java.io.IOExceptionJsonGenerationExceptionJsonMappingException- Since:
- 1.1
-
writeTree
public void writeTree(JsonGenerator jgen, JsonNode rootNode) throws java.io.IOException, JsonProcessingException
Method to serialize given JSON Tree, using generator provided.- Specified by:
writeTreein classObjectCodec- Throws:
java.io.IOExceptionJsonProcessingException
-
writeTree
public void writeTree(JsonGenerator jgen, JsonNode rootNode, SerializationConfig cfg) throws java.io.IOException, JsonProcessingException
Method to serialize given Json Tree, using generator provided.- Throws:
java.io.IOExceptionJsonProcessingException- Since:
- 1.1
-
createObjectNode
public ObjectNode 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:
createObjectNodein classObjectCodec- Since:
- 1.2
-
createArrayNode
public ArrayNode 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:
createArrayNodein classObjectCodec- Since:
- 1.2
-
treeAsTokens
public JsonParser treeAsTokens(JsonNode n)
Method for constructing aJsonParserout of JSON tree representation.- Specified by:
treeAsTokensin classObjectCodec- Parameters:
n- Root node of the tree that resulting parser will read from- Since:
- 1.3
-
treeToValue
public <T> T treeToValue(JsonNode n, java.lang.Class<T> valueType) throws java.io.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:
treeToValuein classObjectCodec- Throws:
java.io.IOExceptionJsonParseExceptionJsonMappingException
-
valueToTree
public <T extends JsonNode> T valueToTree(java.lang.Object fromValue) throws java.lang.IllegalArgumentException
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 basicJsonNodeorObjectNode- Parameters:
fromValue- Bean value to convert- Returns:
- Root node of the resulting JSON tree
- Throws:
java.lang.IllegalArgumentException- Since:
- 1.6
-
canSerialize
public boolean canSerialize(java.lang.Class<?> type)
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
public boolean canDeserialize(JavaType type)
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(java.io.File src, java.lang.Class<T> valueType) throws java.io.IOException, JsonParseException, JsonMappingException- Throws:
java.io.IOExceptionJsonParseExceptionJsonMappingException
-
readValue
public <T> T readValue(java.io.File src, TypeReference valueTypeRef) throws java.io.IOException, JsonParseException, JsonMappingException- Throws:
java.io.IOExceptionJsonParseExceptionJsonMappingException
-
readValue
public <T> T readValue(java.io.File src, JavaType valueType) throws java.io.IOException, JsonParseException, JsonMappingException- Throws:
java.io.IOExceptionJsonParseExceptionJsonMappingException
-
readValue
public <T> T readValue(java.net.URL src, java.lang.Class<T> valueType) throws java.io.IOException, JsonParseException, JsonMappingException- Throws:
java.io.IOExceptionJsonParseExceptionJsonMappingException
-
readValue
public <T> T readValue(java.net.URL src, TypeReference valueTypeRef) throws java.io.IOException, JsonParseException, JsonMappingException- Throws:
java.io.IOExceptionJsonParseExceptionJsonMappingException
-
readValue
public <T> T readValue(java.net.URL src, JavaType valueType) throws java.io.IOException, JsonParseException, JsonMappingException- Throws:
java.io.IOExceptionJsonParseExceptionJsonMappingException
-
readValue
public <T> T readValue(java.lang.String content, java.lang.Class<T> valueType) throws java.io.IOException, JsonParseException, JsonMappingException- Throws:
java.io.IOExceptionJsonParseExceptionJsonMappingException
-
readValue
public <T> T readValue(java.lang.String content, TypeReference valueTypeRef) throws java.io.IOException, JsonParseException, JsonMappingException- Throws:
java.io.IOExceptionJsonParseExceptionJsonMappingException
-
readValue
public <T> T readValue(java.lang.String content, JavaType valueType) throws java.io.IOException, JsonParseException, JsonMappingException- Throws:
java.io.IOExceptionJsonParseExceptionJsonMappingException
-
readValue
public <T> T readValue(java.io.Reader src, java.lang.Class<T> valueType) throws java.io.IOException, JsonParseException, JsonMappingException- Throws:
java.io.IOExceptionJsonParseExceptionJsonMappingException
-
readValue
public <T> T readValue(java.io.Reader src, TypeReference valueTypeRef) throws java.io.IOException, JsonParseException, JsonMappingException- Throws:
java.io.IOExceptionJsonParseExceptionJsonMappingException
-
readValue
public <T> T readValue(java.io.Reader src, JavaType valueType) throws java.io.IOException, JsonParseException, JsonMappingException- Throws:
java.io.IOExceptionJsonParseExceptionJsonMappingException
-
readValue
public <T> T readValue(java.io.InputStream src, java.lang.Class<T> valueType) throws java.io.IOException, JsonParseException, JsonMappingException- Throws:
java.io.IOExceptionJsonParseExceptionJsonMappingException
-
readValue
public <T> T readValue(java.io.InputStream src, TypeReference valueTypeRef) throws java.io.IOException, JsonParseException, JsonMappingException- Throws:
java.io.IOExceptionJsonParseExceptionJsonMappingException
-
readValue
public <T> T readValue(java.io.InputStream src, JavaType valueType) throws java.io.IOException, JsonParseException, JsonMappingException- Throws:
java.io.IOExceptionJsonParseExceptionJsonMappingException
-
readValue
public <T> T readValue(byte[] src, java.lang.Class<T> valueType) throws java.io.IOException, JsonParseException, JsonMappingException- Throws:
java.io.IOExceptionJsonParseExceptionJsonMappingException- Since:
- 1.8
-
readValue
public <T> T readValue(byte[] src, int offset, int len, java.lang.Class<T> valueType) throws java.io.IOException, JsonParseException, JsonMappingException- Throws:
java.io.IOExceptionJsonParseExceptionJsonMappingException
-
readValue
public <T> T readValue(byte[] src, TypeReference valueTypeRef) throws java.io.IOException, JsonParseException, JsonMappingException- Throws:
java.io.IOExceptionJsonParseExceptionJsonMappingException- Since:
- 1.8
-
readValue
public <T> T readValue(byte[] src, int offset, int len, TypeReference valueTypeRef) throws java.io.IOException, JsonParseException, JsonMappingException- Throws:
java.io.IOExceptionJsonParseExceptionJsonMappingException
-
readValue
public <T> T readValue(byte[] src, JavaType valueType) throws java.io.IOException, JsonParseException, JsonMappingException- Throws:
java.io.IOExceptionJsonParseExceptionJsonMappingException- Since:
- 1.8
-
readValue
public <T> T readValue(byte[] src, int offset, int len, JavaType valueType) throws java.io.IOException, JsonParseException, JsonMappingException- Throws:
java.io.IOExceptionJsonParseExceptionJsonMappingException
-
readValue
public <T> T readValue(JsonNode root, java.lang.Class<T> valueType) throws java.io.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:
java.io.IOExceptionJsonParseExceptionJsonMappingException- Since:
- 1.6
-
readValue
public <T> T readValue(JsonNode root, TypeReference valueTypeRef) throws java.io.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:
java.io.IOExceptionJsonParseExceptionJsonMappingException- Since:
- 1.6
-
readValue
public <T> T readValue(JsonNode root, JavaType valueType) throws java.io.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:
java.io.IOExceptionJsonParseExceptionJsonMappingException- Since:
- 1.6
-
writeValue
public void writeValue(java.io.File resultFile, java.lang.Object value) throws java.io.IOException, JsonGenerationException, JsonMappingExceptionMethod that can be used to serialize any Java value as JSON output, written to File provided.- Throws:
java.io.IOExceptionJsonGenerationExceptionJsonMappingException
-
writeValue
public void writeValue(java.io.OutputStream out, java.lang.Object value) throws java.io.IOException, JsonGenerationException, JsonMappingExceptionMethod 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,
JsonFactorythis 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:
java.io.IOExceptionJsonGenerationExceptionJsonMappingException
-
writeValue
public void writeValue(java.io.Writer w, java.lang.Object value) throws java.io.IOException, JsonGenerationException, JsonMappingExceptionMethod 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,
JsonFactorythis 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:
java.io.IOExceptionJsonGenerationExceptionJsonMappingException
-
writeValueAsString
public java.lang.String writeValueAsString(java.lang.Object value) throws java.io.IOException, JsonGenerationException, JsonMappingExceptionMethod 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:
java.io.IOExceptionJsonGenerationExceptionJsonMappingException- Since:
- 1.3
-
writeValueAsBytes
public byte[] writeValueAsBytes(java.lang.Object value) throws java.io.IOException, JsonGenerationException, JsonMappingExceptionMethod 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:
java.io.IOExceptionJsonGenerationExceptionJsonMappingException- Since:
- 1.5
-
writer
public ObjectWriter writer()
Convenience method for constructingObjectWriterwith default settings.- Since:
- 1.6
-
writer
public ObjectWriter writer(java.text.DateFormat df)
Factory method for constructingObjectWriterthat will serialize objects using specifiedDateFormat; or, if null passed, using timestamp (64-bit number.- Since:
- 1.9
-
writerWithView
public ObjectWriter writerWithView(java.lang.Class<?> serializationView)
Factory method for constructingObjectWriterthat will serialize objects using specified JSON View (filter).- Since:
- 1.9
-
writerWithType
public ObjectWriter writerWithType(java.lang.Class<?> rootType)
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.- Since:
- 1.9
-
writerWithType
public ObjectWriter writerWithType(JavaType rootType)
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.- Since:
- 1.9
-
writerWithType
public ObjectWriter writerWithType(TypeReference<?> rootType)
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.- Since:
- 1.9
-
writer
public ObjectWriter writer(PrettyPrinter pp)
Factory method for constructingObjectWriterthat will serialize objects using specified pretty printer for indentation (or if null, no pretty printer)- Since:
- 1.9
-
writerWithDefaultPrettyPrinter
public ObjectWriter writerWithDefaultPrettyPrinter()
Factory method for constructingObjectWriterthat will serialize objects using the default pretty printer for indentation- Since:
- 1.9
-
writer
public ObjectWriter writer(FilterProvider filterProvider)
Factory method for constructingObjectWriterthat will serialize objects using specified filter provider.- Since:
- 1.9
-
writer
public ObjectWriter writer(FormatSchema schema)
Factory method for constructingObjectWriterthat will pass specific schema object toJsonGeneratorused for writing content.- Parameters:
schema- Schema to pass to generator- Since:
- 1.9
-
typedWriter
@Deprecated public ObjectWriter typedWriter(java.lang.Class<?> rootType)
Deprecated.Since 1.9, usewriterWithType(Class)instead.
-
typedWriter
@Deprecated public ObjectWriter typedWriter(JavaType rootType)
Deprecated.Since 1.9, usewriterWithType(JavaType)instead.
-
typedWriter
@Deprecated public ObjectWriter typedWriter(TypeReference<?> rootType)
Deprecated.Since 1.9, usewriterWithType(TypeReference)instead.
-
viewWriter
@Deprecated public ObjectWriter viewWriter(java.lang.Class<?> serializationView)
Deprecated.Since 1.9, usewriterWithView(Class)instead.
-
prettyPrintingWriter
@Deprecated public ObjectWriter prettyPrintingWriter(PrettyPrinter pp)
Deprecated.Since 1.9, usewriter(FilterProvider)instead.
-
defaultPrettyPrintingWriter
@Deprecated public ObjectWriter defaultPrettyPrintingWriter()
Deprecated.Since 1.9, usewriterWithDefaultPrettyPrinter()instead.
-
filteredWriter
@Deprecated public ObjectWriter filteredWriter(FilterProvider filterProvider)
Deprecated.Since 1.9, usewriter(FilterProvider)instead.
-
schemaBasedWriter
@Deprecated public ObjectWriter schemaBasedWriter(FormatSchema schema)
Deprecated.Since 1.9, usewriter(FilterProvider)instead.
-
reader
public ObjectReader reader()
Factory method for constructingObjectReaderwith default settings. Note that the resulting instance is NOT usable as is, without defining expected value type.- Since:
- 1.6
-
readerForUpdating
public ObjectReader readerForUpdating(java.lang.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. 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
public ObjectReader reader(JavaType type)
Factory method for constructingObjectReaderthat will read or update instances of specified type- Since:
- 1.6
-
reader
public ObjectReader reader(java.lang.Class<?> type)
Factory method for constructingObjectReaderthat will read or update instances of specified type- Since:
- 1.6
-
reader
public ObjectReader reader(TypeReference<?> type)
Factory method for constructingObjectReaderthat will read or update instances of specified type- Since:
- 1.6
-
reader
public ObjectReader reader(JsonNodeFactory f)
Factory method for constructingObjectReaderthat will use specifiedJsonNodeFactoryfor constructing JSON trees.- Since:
- 1.6
-
reader
public ObjectReader reader(FormatSchema schema)
Factory method for constructingObjectReaderthat will pass specific schema object toJsonParserused for reading content.- Parameters:
schema- Schema to pass to parser- Since:
- 1.8
-
reader
public ObjectReader reader(InjectableValues injectableValues)
Factory method for constructingObjectReaderthat will use specified injectable values.- Parameters:
injectableValues- Injectable values to use- Since:
- 1.9
-
updatingReader
@Deprecated public ObjectReader updatingReader(java.lang.Object valueToUpdate)
Deprecated.Since 1.9, usereaderForUpdating(java.lang.Object)instead.
-
schemaBasedReader
@Deprecated public ObjectReader schemaBasedReader(FormatSchema schema)
Deprecated.Since 1.9, usereader(FormatSchema)instead.
-
convertValue
public <T> T convertValue(java.lang.Object fromValue, java.lang.Class<T> toValueType) throws java.lang.IllegalArgumentExceptionConvenience 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:
java.lang.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(java.lang.Object fromValue, TypeReference toValueTypeRef) throws java.lang.IllegalArgumentException- Throws:
java.lang.IllegalArgumentException
-
convertValue
public <T> T convertValue(java.lang.Object fromValue, JavaType toValueType) throws java.lang.IllegalArgumentException- Throws:
java.lang.IllegalArgumentException
-
_convert
protected java.lang.Object _convert(java.lang.Object fromValue, JavaType toValueType) throws java.lang.IllegalArgumentException- Throws:
java.lang.IllegalArgumentException
-
generateJsonSchema
public JsonSchema generateJsonSchema(java.lang.Class<?> t) throws JsonMappingException
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(java.lang.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
protected PrettyPrinter _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, java.lang.Object value) throws java.io.IOException, JsonGenerationException, JsonMappingException
Method called to configure the generator as necessary and then call write functionality- Throws:
java.io.IOExceptionJsonGenerationExceptionJsonMappingException
-
_configAndWriteValue
protected final void _configAndWriteValue(JsonGenerator jgen, java.lang.Object value, java.lang.Class<?> viewClass) throws java.io.IOException, JsonGenerationException, JsonMappingException
- Throws:
java.io.IOExceptionJsonGenerationExceptionJsonMappingException
-
_readValue
protected java.lang.Object _readValue(DeserializationConfig cfg, JsonParser jp, JavaType valueType) throws java.io.IOException, JsonParseException, JsonMappingException
Actual implementation of value reading+binding operation.- Throws:
java.io.IOExceptionJsonParseExceptionJsonMappingException
-
_readMapAndClose
protected java.lang.Object _readMapAndClose(JsonParser jp, JavaType valueType) throws java.io.IOException, JsonParseException, JsonMappingException
- Throws:
java.io.IOExceptionJsonParseExceptionJsonMappingException
-
_initForReading
protected JsonToken _initForReading(JsonParser jp) throws java.io.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:
java.io.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 java.lang.Object _unwrapAndDeserialize(JsonParser jp, JavaType rootType, DeserializationContext ctxt, JsonDeserializer<java.lang.Object> deser) throws java.io.IOException, JsonParseException, JsonMappingException
- Throws:
java.io.IOExceptionJsonParseExceptionJsonMappingException
-
_findRootDeserializer
protected JsonDeserializer<java.lang.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)
-
-