|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.codehaus.jackson.ObjectCodec
org.codehaus.jackson.map.ObjectMapper
public class ObjectMapper
This mapper (or, data binder, or codec) provides functionality for
conversting between Java objects (instances of JDK provided core classes,
beans), and matching JSON constructs.
It will use instances of 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 | |
---|---|
static class |
ObjectMapper.DefaultTypeResolverBuilder
Customized TypeResolverBuilder that provides
resolver builders based on its configuration. |
static class |
ObjectMapper.DefaultTyping
Enumeration used with enableDefaultTyping()
to specify what kind of types (classes) default typing should
be used for. |
Field Summary | |
---|---|
protected TypeResolverBuilder<?> |
_defaultTyper
Object that defines how to add type information for types that do not have explicit type information settings (which are usually indicated by JsonTypeInfo )
If set to null, no type information will be added unless annotations
are used; if set to non-null, resolver builder is used to check
which type serializers and deserializers are to be used (if any) |
protected DeserializationConfig |
_deserializationConfig
Configuration object that defines basic global settings for the serialization process |
protected DeserializerProvider |
_deserializerProvider
Object that manages access to deserializers used for deserializing JSON content into Java objects, including possible caching of the deserializers. |
protected JsonFactory |
_jsonFactory
Factory used to create JsonParser and JsonGenerator
instances as necessary. |
protected JsonNodeFactory |
_nodeFactory
Node factory to use for creating JsonNode s
for tree model instances when binding JSON content
as JSON trees. |
protected ConcurrentHashMap<JavaType,JsonDeserializer<Object>> |
_rootDeserializers
We will use a separate main-level Map for keeping track of root-level deserializers. |
protected SerializationConfig |
_serializationConfig
Configuration object that defines basic global settings for the serialization process |
protected SerializerFactory |
_serializerFactory
Serializer factory used for constructing serializers. |
protected SerializerProvider |
_serializerProvider
Object that manages access to serializers used for serialization, including caching. |
protected VisibilityChecker<?> |
_visibilityChecker
Object used for determining whether specific property elements (method, constructors, fields) can be auto-detected based on their visibility (access modifiers). |
protected static AnnotationIntrospector |
DEFAULT_ANNOTATION_INTROSPECTOR
|
protected static ClassIntrospector<? extends BeanDescription> |
DEFAULT_INTROSPECTOR
|
protected static VisibilityChecker<?> |
STD_VISIBILITY_CHECKER
|
Constructor Summary | |
---|---|
ObjectMapper()
Default constructor, which will construct the default JsonFactory as necessary, use
StdSerializerProvider as its
SerializerProvider , and
BeanSerializerFactory as its
SerializerFactory . |
|
ObjectMapper(JsonFactory jf)
Construct mapper that uses specified JsonFactory
for constructing necessary JsonParser s and/or
JsonGenerator s. |
|
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 with setSerializerFactory(org.codehaus.jackson.map.SerializerFactory) |
Method Summary | ||
---|---|---|
protected void |
_configAndWriteValue(JsonGenerator jgen,
Object value)
Method called to configure the generator as necessary and then call write functionality |
|
protected void |
_configAndWriteValue(JsonGenerator jgen,
Object value,
Class<?> viewClass)
|
|
protected Object |
_convert(Object fromValue,
JavaType toValueType)
|
|
protected DeserializationContext |
_createDeserializationContext(JsonParser jp,
DeserializationConfig cfg)
|
|
protected JsonDeserializer<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 Object |
_readMapAndClose(JsonParser jp,
JavaType valueType)
|
|
protected Object |
_readValue(DeserializationConfig cfg,
JsonParser jp,
JavaType valueType)
Actual implementation of value reading+binding operation. |
|
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. |
|
ObjectMapper |
configure(DeserializationConfig.Feature f,
boolean state)
Method for changing state of an on/off deserialization feature for this object mapper. |
|
ObjectMapper |
configure(JsonGenerator.Feature f,
boolean state)
Method for changing state of an on/off JsonGenerator feature for
JsonFactory instance this object mapper uses. |
|
ObjectMapper |
configure(JsonParser.Feature f,
boolean state)
Method for changing state of an on/off JsonParser feature for
JsonFactory instance this object mapper uses. |
|
ObjectMapper |
configure(SerializationConfig.Feature f,
boolean state)
Method for changing state of an on/off serialization feature for this object mapper. |
|
|
convertValue(Object fromValue,
Class<T> toValueType)
Convenience method for doing two-step conversion from given value, into instance of given value type. |
|
|
convertValue(Object fromValue,
JavaType toValueType)
|
|
|
convertValue(Object fromValue,
TypeReference toValueTypeRef)
|
|
DeserializationConfig |
copyDeserializationConfig()
Method that creates a copy of the shared default DeserializationConfig object
that defines configuration settings for deserialization. |
|
SerializationConfig |
copySerializationConfig()
Method that creates a copy of the shared default SerializationConfig object
that defines configuration settings for serialization. |
|
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) |
|
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) |
|
ObjectMapper |
disableDefaultTyping()
|
|
ObjectMapper |
enableDefaultTyping()
Convenience method that is equivalant to calling |
|
ObjectMapper |
enableDefaultTyping(ObjectMapper.DefaultTyping dti)
Convenience method that is equivalant to calling |
|
ObjectMapper |
enableDefaultTyping(ObjectMapper.DefaultTyping dti,
JsonTypeInfo.As includeAs)
|
|
JsonSchema |
generateJsonSchema(Class<?> t)
Generate Json-schema instance for specified class. |
|
JsonSchema |
generateJsonSchema(Class<?> t,
SerializationConfig cfg)
Generate Json-schema instance for specified class, using specific serialization configuration |
|
DeserializationConfig |
getDeserializationConfig()
Method that returns the shared default DeserializationConfig object
that defines configuration settings for deserialization. |
|
DeserializerProvider |
getDeserializerProvider()
|
|
JsonFactory |
getJsonFactory()
Method that can be used to get hold of JsonFactory that this
mapper uses if it needs to construct JsonParser s
and/or JsonGenerator s. |
|
JsonNodeFactory |
getNodeFactory()
Method that can be used to get hold of JsonNodeFactory
that this mapper will use when directly constructing
root JsonNode instances for Trees. |
|
SerializationConfig |
getSerializationConfig()
Method that returns the shared default SerializationConfig object
that defines configuration settings for serialization. |
|
SerializerProvider |
getSerializerProvider()
|
|
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. |
|
JsonNode |
readTree(InputStream in)
Method to deserialize JSON content as tree expressed using set of JsonNode instances. |
|
JsonNode |
readTree(JsonParser jp)
Method to deserialize JSON content as tree expressed using set of JsonNode instances. |
|
JsonNode |
readTree(JsonParser jp,
DeserializationConfig cfg)
Method to deserialize JSON content as tree expressed using set of JsonNode instances. |
|
JsonNode |
readTree(Reader r)
Method to deserialize JSON content as tree expressed using set of JsonNode instances. |
|
JsonNode |
readTree(String content)
Method to deserialize JSON content as tree expressed using set of JsonNode instances. |
|
|
readValue(byte[] src,
int offset,
int len,
Class<T> valueType)
|
|
|
readValue(byte[] src,
int offset,
int len,
JavaType valueType)
|
|
|
readValue(byte[] src,
int offset,
int len,
TypeReference valueTypeRef)
|
|
|
readValue(File src,
Class<T> valueType)
|
|
|
readValue(File src,
JavaType valueType)
|
|
|
readValue(File src,
TypeReference valueTypeRef)
|
|
|
readValue(InputStream src,
Class<T> valueType)
|
|
|
readValue(InputStream src,
JavaType valueType)
|
|
|
readValue(InputStream src,
TypeReference valueTypeRef)
|
|
|
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 (like Boolean ). |
|
|
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 (like Boolean ). |
|
|
readValue(JsonParser jp,
JavaType valueType)
Method to deserialize Json content into a Java type, reference to which is passed as argument. |
|
|
readValue(JsonParser jp,
JavaType valueType,
DeserializationConfig cfg)
Method to deserialize Json content into a Java type, reference to which is passed as argument. |
|
|
readValue(JsonParser jp,
TypeReference<?> valueTypeRef)
Method to deserialize Json content into a Java type, reference to which is passed as argument. |
|
|
readValue(JsonParser jp,
TypeReference<?> valueTypeRef,
DeserializationConfig cfg)
Method to deserialize Json content into a Java type, reference to which is passed as argument. |
|
|
readValue(Reader src,
Class<T> valueType)
|
|
|
readValue(Reader src,
JavaType valueType)
|
|
|
readValue(Reader src,
TypeReference valueTypeRef)
|
|
|
readValue(String content,
Class<T> valueType)
|
|
|
readValue(String content,
JavaType valueType)
|
|
|
readValue(String content,
TypeReference valueTypeRef)
|
|
|
readValue(URL src,
Class<T> valueType)
|
|
|
readValue(URL src,
JavaType valueType)
|
|
|
readValue(URL src,
TypeReference valueTypeRef)
|
|
ObjectMapper |
setDefaltTyping(TypeResolverBuilder<?> typer)
|
|
ObjectMapper |
setDeserializationConfig(DeserializationConfig cfg)
Method for replacing the shared default deserialization configuration object. |
|
ObjectMapper |
setDeserializerProvider(DeserializerProvider p)
Method for setting specific DeserializerProvider to use
for handling caching of JsonDeserializer instances. |
|
ObjectMapper |
setNodeFactory(JsonNodeFactory f)
Method for specifying JsonNodeFactory to use for
constructing root level tree nodes (via method
createObjectNode() |
|
ObjectMapper |
setSerializationConfig(SerializationConfig cfg)
Method for replacing the shared default serialization configuration object. |
|
ObjectMapper |
setSerializerFactory(SerializerFactory f)
Method for setting specific SerializerFactory to use
for constructing (bean) serializers. |
|
ObjectMapper |
setSerializerProvider(SerializerProvider p)
Method for setting specific SerializerProvider to use
for handling caching of JsonSerializer instances. |
|
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. |
|
JsonParser |
treeAsTokens(JsonNode n)
Method for constructing a JsonParser for reading
contents of a JSON tree, as if it was external serialized
JSON content. |
|
|
treeToValue(JsonNode n,
Class<T> valueType)
Convenience method for converting given JSON tree into instance of specified value type. |
|
ObjectWriter |
typedWriter(Class<?> rootType)
Factory method for constructing ObjectWriter that will
serialize objects using specified root type, instead of actual
runtime type of value. |
|
ObjectWriter |
typedWriter(JavaType rootType)
Factory method for constructing ObjectWriter that will
serialize objects using specified root type, instead of actual
runtime type of value. |
|
ObjectWriter |
viewWriter(Class<?> serializationView)
Factory method for constructing ObjectWriter 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(JsonGenerator jgen,
Object value)
Method that can be used to serialize any Java value as JSON output, using provided JsonGenerator . |
|
void |
writeValue(JsonGenerator jgen,
Object value,
SerializationConfig config)
Method that can be used to serialize any Java value as JSON output, using provided JsonGenerator ,
configured as per passed configuration object. |
|
void |
writeValue(OutputStream out,
Object value)
Method that can be used to serialize any Java value as JSON output, using output stream provided (using encoding JsonEncoding.UTF8 ). |
|
void |
writeValue(Writer w,
Object value)
Method that can be used to serialize any Java value as JSON output, using Writer provided. |
|
byte[] |
writeValueAsBytes(Object value)
Method that can be used to serialize any Java value as a byte array. |
|
String |
writeValueAsString(Object value)
Method that can be used to serialize any Java value as a String. |
|
void |
writeValueUsingView(JsonGenerator jgen,
Object value,
Class<?> viewClass)
Deprecated. Use viewWriter(java.lang.Class>) instead |
|
void |
writeValueUsingView(OutputStream out,
Object value,
Class<?> viewClass)
Deprecated. Use viewWriter(java.lang.Class>) instead |
|
void |
writeValueUsingView(Writer w,
Object value,
Class<?> viewClass)
Deprecated. Use viewWriter(java.lang.Class>) instead |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected static final ClassIntrospector<? extends BeanDescription> DEFAULT_INTROSPECTOR
protected static final AnnotationIntrospector DEFAULT_ANNOTATION_INTROSPECTOR
protected static final VisibilityChecker<?> STD_VISIBILITY_CHECKER
protected final JsonFactory _jsonFactory
JsonParser
and JsonGenerator
instances as necessary.
protected TypeResolverBuilder<?> _defaultTyper
JsonTypeInfo
)
If set to null, no type information will be added unless annotations
are used; if set to non-null, resolver builder is used to check
which type serializers and deserializers are to be used (if any)
protected VisibilityChecker<?> _visibilityChecker
JsonAutoDetect
annotation)
protected SerializationConfig _serializationConfig
protected SerializerProvider _serializerProvider
_serializerFactory
to allow
for constructing custom serializers.
protected SerializerFactory _serializerFactory
protected DeserializationConfig _deserializationConfig
protected DeserializerProvider _deserializerProvider
DeserializerFactory
to use for constructing acutal deserializers.
protected JsonNodeFactory _nodeFactory
JsonNode
s
for tree model instances when binding JSON content
as JSON trees.
protected final ConcurrentHashMap<JavaType,JsonDeserializer<Object>> _rootDeserializers
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 |
---|
public ObjectMapper()
JsonFactory
as necessary, use
StdSerializerProvider
as its
SerializerProvider
, and
BeanSerializerFactory
as its
SerializerFactory
.
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.
public ObjectMapper(JsonFactory jf)
JsonFactory
for constructing necessary JsonParser
s and/or
JsonGenerator
s.
public ObjectMapper(SerializerFactory sf)
setSerializerFactory(org.codehaus.jackson.map.SerializerFactory)
SerializerFactory
for constructing necessary serializers.
public ObjectMapper(JsonFactory jf, SerializerProvider sp, DeserializerProvider dp)
public ObjectMapper(JsonFactory jf, SerializerProvider sp, DeserializerProvider dp, SerializationConfig sconfig, DeserializationConfig dconfig)
jf
- JsonFactory to use: if null, a new MappingJsonFactory
will be constructedsp
- SerializerProvider to use: if null, a StdSerializerProvider
will be constructeddp
- DeserializerProvider to use: if null, a StdDeserializerProvider
will be constructedsconfig
- Serialization configuration to use; if null, basic SerializationConfig
will be constructeddconfig
- Deserialization configuration to use; if null, basic DeserializationConfig
will be constructedMethod Detail |
---|
public ObjectMapper setSerializerFactory(SerializerFactory f)
SerializerFactory
to use
for constructing (bean) serializers.
public ObjectMapper setSerializerProvider(SerializerProvider p)
SerializerProvider
to use
for handling caching of JsonSerializer
instances.
public SerializerProvider getSerializerProvider()
public ObjectMapper setDeserializerProvider(DeserializerProvider p)
DeserializerProvider
to use
for handling caching of JsonDeserializer
instances.
public DeserializerProvider getDeserializerProvider()
public ObjectMapper setNodeFactory(JsonNodeFactory f)
JsonNodeFactory
to use for
constructing root level tree nodes (via method
createObjectNode()
public VisibilityChecker<?> getVisibilityChecker()
public void setVisibilityChecker(VisibilityChecker<?> vc)
public SerializationConfig getSerializationConfig()
SerializationConfig
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
public SerializationConfig copySerializationConfig()
SerializationConfig
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 separate SerializationConfig
argument.
The use case is that of changing object settings of the configuration
(like date format being used, see SerializationConfig.setDateFormat(java.text.DateFormat)
).
public ObjectMapper setSerializationConfig(SerializationConfig cfg)
public ObjectMapper configure(SerializationConfig.Feature f, boolean state)
This is method is basically a shortcut method for calling
SerializationConfig.set(org.codehaus.jackson.map.SerializationConfig.Feature, boolean)
on the shared SerializationConfig
object with given arguments.
public DeserializationConfig getDeserializationConfig()
DeserializationConfig
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
public DeserializationConfig copyDeserializationConfig()
DeserializationConfig
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 separate DeserializationConfig
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)
)
public ObjectMapper setDeserializationConfig(DeserializationConfig cfg)
public ObjectMapper configure(DeserializationConfig.Feature f, boolean state)
This is method is basically a shortcut method for calling
DeserializationConfig.set(org.codehaus.jackson.map.DeserializationConfig.Feature, boolean)
on the shared DeserializationConfig
object with given arguments.
public JsonFactory getJsonFactory()
JsonFactory
that this
mapper uses if it needs to construct JsonParser
s
and/or JsonGenerator
s.
JsonFactory
that this mapper uses when it needs to
construct Json parser and generatorspublic ObjectMapper configure(JsonParser.Feature f, boolean state)
JsonParser
feature for
JsonFactory
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 shared
JsonFactory
this mapper uses (which is accessible
using getJsonFactory()
).
public ObjectMapper configure(JsonGenerator.Feature f, boolean state)
JsonGenerator
feature for
JsonFactory
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 shared
JsonFactory
this mapper uses (which is accessible
using getJsonFactory()
).
public JsonNodeFactory getNodeFactory()
JsonNodeFactory
that this mapper will use when directly constructing
root JsonNode
instances for Trees.
public ObjectMapper enableDefaultTyping()
enableObjectTyping(DefaultTyping.OBJECT_AND_NON_CONCRETE);
public ObjectMapper enableDefaultTyping(ObjectMapper.DefaultTyping dti)
enableObjectTyping(dti, JsonTypeInfo.As.WRAPPER_ARRAY);
public ObjectMapper enableDefaultTyping(ObjectMapper.DefaultTyping dti, JsonTypeInfo.As includeAs)
public ObjectMapper disableDefaultTyping()
public ObjectMapper setDefaltTyping(TypeResolverBuilder<?> typer)
public <T> T readValue(JsonParser jp, Class<T> valueType) throws IOException, JsonParseException, JsonMappingException
Boolean
).
Note: this method should NOT be used if the result type is a
container (Collection
or Map
.
The reason is that due to type erasure, key and value types
can not be introspected when using this method.
readValue
in class ObjectCodec
IOException
JsonParseException
JsonMappingException
public <T> T readValue(JsonParser jp, Class<T> valueType, DeserializationConfig cfg) throws IOException, JsonParseException, JsonMappingException
Boolean
).
Note: this method should NOT be used if the result type is a
container (Collection
or Map
.
The reason is that due to type erasure, key and value types
can not be introspected when using this method.
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)
IOException
JsonParseException
JsonMappingException
public <T> T readValue(JsonParser jp, TypeReference<?> valueTypeRef) throws IOException, JsonParseException, JsonMappingException
readValue
in class ObjectCodec
IOException
JsonParseException
JsonMappingException
public <T> T readValue(JsonParser jp, TypeReference<?> valueTypeRef, DeserializationConfig cfg) throws IOException, JsonParseException, JsonMappingException
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)
IOException
JsonParseException
JsonMappingException
public <T> T readValue(JsonParser jp, JavaType valueType) throws IOException, JsonParseException, JsonMappingException
TypeFactory
.
readValue
in class ObjectCodec
IOException
JsonParseException
JsonMappingException
public <T> T readValue(JsonParser jp, JavaType valueType, DeserializationConfig cfg) throws IOException, JsonParseException, JsonMappingException
TypeFactory
.
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)
IOException
JsonParseException
JsonMappingException
public JsonNode readTree(JsonParser jp) throws IOException, JsonProcessingException
JsonNode
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).
readTree
in class ObjectCodec
IOException
JsonProcessingException
public JsonNode readTree(JsonParser jp, DeserializationConfig cfg) throws IOException, JsonProcessingException
JsonNode
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).
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)
IOException
JsonProcessingException
public JsonNode readTree(InputStream in) throws IOException, JsonProcessingException
JsonNode
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).
in
- Input stream used to read JSON content
for building the JSON tree.
IOException
JsonProcessingException
public JsonNode readTree(Reader r) throws IOException, JsonProcessingException
JsonNode
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).
r
- Reader used to read JSON content
for building the JSON tree.
IOException
JsonProcessingException
public JsonNode readTree(String content) throws IOException, JsonProcessingException
JsonNode
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).
content
- JSON content to parse
for building the JSON tree.
IOException
JsonProcessingException
public void writeValue(JsonGenerator jgen, Object value) throws IOException, JsonGenerationException, JsonMappingException
JsonGenerator
.
writeValue
in class ObjectCodec
IOException
JsonGenerationException
JsonMappingException
public void writeValue(JsonGenerator jgen, Object value, SerializationConfig config) throws IOException, JsonGenerationException, JsonMappingException
JsonGenerator
,
configured as per passed configuration object.
IOException
JsonGenerationException
JsonMappingException
public void writeTree(JsonGenerator jgen, JsonNode rootNode) throws IOException, JsonProcessingException
writeTree
in class ObjectCodec
IOException
JsonProcessingException
public void writeTree(JsonGenerator jgen, JsonNode rootNode, SerializationConfig cfg) throws IOException, JsonProcessingException
IOException
JsonProcessingException
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)
createObjectNode
in class ObjectCodec
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)
createArrayNode
in class ObjectCodec
public JsonParser treeAsTokens(JsonNode n)
ObjectCodec
JsonParser
for reading
contents of a JSON tree, as if it was external serialized
JSON content.
treeAsTokens
in class ObjectCodec
public <T> T treeToValue(JsonNode n, Class<T> valueType) throws IOException, JsonParseException, JsonMappingException
ObjectCodec
JsonParser
to
iterate over contents of the tree, and using that parser for data binding.
treeToValue
in class ObjectCodec
IOException
JsonParseException
JsonMappingException
public boolean canSerialize(Class<?> type)
public boolean canDeserialize(JavaType type)
public <T> T readValue(File src, Class<T> valueType) throws IOException, JsonParseException, JsonMappingException
IOException
JsonParseException
JsonMappingException
public <T> T readValue(File src, TypeReference valueTypeRef) throws IOException, JsonParseException, JsonMappingException
IOException
JsonParseException
JsonMappingException
public <T> T readValue(File src, JavaType valueType) throws IOException, JsonParseException, JsonMappingException
IOException
JsonParseException
JsonMappingException
public <T> T readValue(URL src, Class<T> valueType) throws IOException, JsonParseException, JsonMappingException
IOException
JsonParseException
JsonMappingException
public <T> T readValue(URL src, TypeReference valueTypeRef) throws IOException, JsonParseException, JsonMappingException
IOException
JsonParseException
JsonMappingException
public <T> T readValue(URL src, JavaType valueType) throws IOException, JsonParseException, JsonMappingException
IOException
JsonParseException
JsonMappingException
public <T> T readValue(String content, Class<T> valueType) throws IOException, JsonParseException, JsonMappingException
IOException
JsonParseException
JsonMappingException
public <T> T readValue(String content, TypeReference valueTypeRef) throws IOException, JsonParseException, JsonMappingException
IOException
JsonParseException
JsonMappingException
public <T> T readValue(String content, JavaType valueType) throws IOException, JsonParseException, JsonMappingException
IOException
JsonParseException
JsonMappingException
public <T> T readValue(Reader src, Class<T> valueType) throws IOException, JsonParseException, JsonMappingException
IOException
JsonParseException
JsonMappingException
public <T> T readValue(Reader src, TypeReference valueTypeRef) throws IOException, JsonParseException, JsonMappingException
IOException
JsonParseException
JsonMappingException
public <T> T readValue(Reader src, JavaType valueType) throws IOException, JsonParseException, JsonMappingException
IOException
JsonParseException
JsonMappingException
public <T> T readValue(InputStream src, Class<T> valueType) throws IOException, JsonParseException, JsonMappingException
IOException
JsonParseException
JsonMappingException
public <T> T readValue(InputStream src, TypeReference valueTypeRef) throws IOException, JsonParseException, JsonMappingException
IOException
JsonParseException
JsonMappingException
public <T> T readValue(InputStream src, JavaType valueType) throws IOException, JsonParseException, JsonMappingException
IOException
JsonParseException
JsonMappingException
public <T> T readValue(byte[] src, int offset, int len, Class<T> valueType) throws IOException, JsonParseException, JsonMappingException
IOException
JsonParseException
JsonMappingException
public <T> T readValue(byte[] src, int offset, int len, TypeReference valueTypeRef) throws IOException, JsonParseException, JsonMappingException
IOException
JsonParseException
JsonMappingException
public <T> T readValue(byte[] src, int offset, int len, JavaType valueType) throws IOException, JsonParseException, JsonMappingException
IOException
JsonParseException
JsonMappingException
public void writeValue(File resultFile, Object value) throws IOException, JsonGenerationException, JsonMappingException
IOException
JsonGenerationException
JsonMappingException
public void writeValue(OutputStream out, Object value) throws IOException, JsonGenerationException, JsonMappingException
JsonEncoding.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 when JsonGenerator
we construct
is closed).
IOException
JsonGenerationException
JsonMappingException
public void writeValue(Writer w, Object value) throws IOException, JsonGenerationException, JsonMappingException
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 when JsonGenerator
we construct
is closed).
IOException
JsonGenerationException
JsonMappingException
public String writeValueAsString(Object value) throws IOException, JsonGenerationException, JsonMappingException
writeValue(Writer,Object)
with StringWriter
and constructing String, but more efficient.
IOException
JsonGenerationException
JsonMappingException
public byte[] writeValueAsBytes(Object value) throws IOException, JsonGenerationException, JsonMappingException
writeValue(Writer,Object)
with ByteArrayOutputStream
and getting bytes, but more efficient.
Encoding used will be UTF-8.
IOException
JsonGenerationException
JsonMappingException
public void writeValueUsingView(JsonGenerator jgen, Object value, Class<?> viewClass) throws IOException, JsonGenerationException, JsonMappingException
viewWriter(java.lang.Class>)
instead
SerializationConfig
and so this method just assigns
given view to a copy of default configuration of this
mapper. So to use other kinds of destinations, just call
copySerializationConfig()
, call
SerializationConfig.setSerializationView(java.lang.Class>)
method on it,
and pass that configuration to other methods.
jgen
- Generator to use for writing JSON contentvalue
- Value to serializeviewClass
- (optional) Identifier for View to use. If null,
equivalent to passing Object.class
; both of which
mean "default view" (all properties always included)
IOException
JsonGenerationException
JsonMappingException
public void writeValueUsingView(Writer w, Object value, Class<?> viewClass) throws IOException, JsonGenerationException, JsonMappingException
viewWriter(java.lang.Class>)
instead
writeValueUsingView(JsonGenerator,Object,Class)
,
this is a short-cut method.
w
- Writer used for writing JSON contentvalue
- Value to serializeviewClass
- (optional) Identifier for View to use. If null,
equivalent to passing Object.class
; both of which
mean "default view" (all properties always included)
IOException
JsonGenerationException
JsonMappingException
public void writeValueUsingView(OutputStream out, Object value, Class<?> viewClass) throws IOException, JsonGenerationException, JsonMappingException
viewWriter(java.lang.Class>)
instead
writeValueUsingView(JsonGenerator,Object,Class)
,
this is a short-cut method.
out
- Output stream used for writing JSON contentvalue
- Value to serializeviewClass
- (optional) Identifier for View to use. If null,
equivalent to passing Object.class
; both of which
mean "default view" (all properties always included)
IOException
JsonGenerationException
JsonMappingException
public ObjectWriter viewWriter(Class<?> serializationView)
ObjectWriter
that will
serialize objects using specified JSON View (filter).
public ObjectWriter typedWriter(Class<?> rootType)
ObjectWriter
that will
serialize objects using specified root type, instead of actual
runtime type of value. Type must be a super-type of runtime
type.
public ObjectWriter typedWriter(JavaType rootType)
ObjectWriter
that will
serialize objects using specified root type, instead of actual
runtime type of value. Type must be a super-type of runtime
type.
public <T> T convertValue(Object fromValue, Class<T> toValueType) throws IllegalArgumentException
IllegalArgumentException
- If conversion fails due to incompatible type;
if so, root cause will contain underlying checked exception data binding
functionality threwpublic <T> T convertValue(Object fromValue, TypeReference toValueTypeRef) throws IllegalArgumentException
IllegalArgumentException
public <T> T convertValue(Object fromValue, JavaType toValueType) throws IllegalArgumentException
IllegalArgumentException
protected Object _convert(Object fromValue, JavaType toValueType) throws IllegalArgumentException
IllegalArgumentException
public JsonSchema generateJsonSchema(Class<?> t) throws JsonMappingException
t
- The class to generate schema for
JsonMappingException
public JsonSchema generateJsonSchema(Class<?> t, SerializationConfig cfg) throws JsonMappingException
t
- The class to generate schema for
JsonMappingException
protected final void _configAndWriteValue(JsonGenerator jgen, Object value) throws IOException, JsonGenerationException, JsonMappingException
IOException
JsonGenerationException
JsonMappingException
protected final void _configAndWriteValue(JsonGenerator jgen, Object value, Class<?> viewClass) throws IOException, JsonGenerationException, JsonMappingException
IOException
JsonGenerationException
JsonMappingException
protected Object _readValue(DeserializationConfig cfg, JsonParser jp, JavaType valueType) throws IOException, JsonParseException, JsonMappingException
IOException
JsonParseException
JsonMappingException
protected Object _readMapAndClose(JsonParser jp, JavaType valueType) throws IOException, JsonParseException, JsonMappingException
IOException
JsonParseException
JsonMappingException
protected JsonToken _initForReading(JsonParser jp) throws IOException, JsonParseException, JsonMappingException
IOException
- if the underlying input source has problems during
parsing
JsonParseException
- if parser has problems parsing content
JsonMappingException
- if the parser does not have any more
content to map (note: Json "null" value is considered content;
enf-of-stream not)protected JsonDeserializer<Object> _findRootDeserializer(DeserializationConfig cfg, JavaType valueType) throws JsonMappingException
JsonMappingException
protected DeserializationContext _createDeserializationContext(JsonParser jp, DeserializationConfig cfg)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |