|
|||||||||
| 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).
| Field Summary | |
|---|---|
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 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. |
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 ClassIntrospector<? extends BeanDescription> |
DEFAULT_INTROSPECTOR
|
| 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)
|
|
ObjectMapper(JsonFactory jf,
SerializerProvider sp,
DeserializerProvider dp)
|
|
ObjectMapper(JsonFactory jf,
SerializerProvider sp,
DeserializerProvider dp,
SerializationConfig sconfig,
DeserializationConfig dconfig)
|
|
ObjectMapper(SerializerFactory sf)
|
|
| Method Summary | ||
|---|---|---|
protected void |
_configAndWriteValue(JsonGenerator jgen,
java.lang.Object value)
Method called to configure the generator as necessary and then call write functionality |
|
protected DeserializationContext |
_createDeserializationContext(JsonParser jp)
|
|
protected JsonDeserializer<java.lang.Object> |
_findRootDeserializer(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(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(java.lang.Class<?> type)
Method that can be called to check whether mapper thinks it could serialize an instance of given Class. |
|
void |
configure(DeserializationConfig.Feature f,
boolean state)
|
|
void |
configure(SerializationConfig.Feature f,
boolean state)
|
|
DeserializationConfig |
getDeserializationConfig()
|
|
JsonFactory |
getJsonFactory()
Method that can be used to get hold of Json factory that this mapper uses if it needs to construct Json parsers and/or generators. |
|
SerializationConfig |
getSerializationConfig()
|
|
JsonNode |
readTree(JsonParser jp)
Method to deserialize Json content as tree expressed using set of JsonNode instances. |
|
|
readValue(byte[] src,
int offset,
int len,
java.lang.Class<T> valueType)
|
|
|
readValue(byte[] src,
int offset,
int len,
JavaType valueType)
|
|
|
readValue(byte[] src,
int offset,
int len,
TypeReference valueTypeRef)
|
|
|
readValue(java.io.File src,
java.lang.Class<T> valueType)
|
|
|
readValue(java.io.File src,
JavaType valueType)
|
|
|
readValue(java.io.File src,
TypeReference valueTypeRef)
|
|
|
readValue(java.io.InputStream src,
java.lang.Class<T> valueType)
|
|
|
readValue(java.io.InputStream src,
JavaType valueType)
|
|
|
readValue(java.io.InputStream src,
TypeReference valueTypeRef)
|
|
|
readValue(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 (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,
TypeReference<?> valueTypeRef)
Method to deserialize Json content into a Java type, reference to which is passed as argument. |
|
|
readValue(java.io.Reader src,
java.lang.Class<T> valueType)
|
|
|
readValue(java.io.Reader src,
JavaType valueType)
|
|
|
readValue(java.io.Reader src,
TypeReference valueTypeRef)
|
|
|
readValue(java.lang.String content,
java.lang.Class<T> valueType)
|
|
|
readValue(java.lang.String content,
JavaType valueType)
|
|
|
readValue(java.lang.String content,
TypeReference valueTypeRef)
|
|
|
readValue(java.net.URL src,
java.lang.Class<T> valueType)
|
|
|
readValue(java.net.URL src,
JavaType valueType)
|
|
|
readValue(java.net.URL src,
TypeReference valueTypeRef)
|
|
void |
setDeserializationConfig(DeserializationConfig cfg)
|
|
void |
setDeserializerProvider(DeserializerProvider p)
|
|
void |
setSerializationConfig(SerializationConfig cfg)
|
|
void |
setSerializerFactory(SerializerFactory f)
|
|
void |
setSerializerProvider(SerializerProvider p)
|
|
void |
writeTree(JsonGenerator jgen,
JsonNode rootNode)
Method to serialize given Json Tree, using generator provided. |
|
void |
writeValue(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. |
|
void |
writeValue(JsonGenerator jgen,
java.lang.Object value)
Method that can be used to serialize any Java value as Json output, using provided JsonGenerator. |
|
void |
writeValue(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 encoding {link JsonEncoding#UTF8}). |
|
void |
writeValue(java.io.Writer w,
java.lang.Object value)
Method that can be used to serialize any Java value as Json output, using Writer provided. |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected final ClassIntrospector<? extends BeanDescription> DEFAULT_INTROSPECTOR
protected final JsonFactory _jsonFactory
JsonParser and JsonGenerator
instances as necessary.
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 final java.util.concurrent.ConcurrentHashMap<JavaType,JsonDeserializer<java.lang.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.
| 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)
public ObjectMapper(SerializerFactory sf)
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 constructed| Method Detail |
|---|
public void setSerializerFactory(SerializerFactory f)
public void setSerializerProvider(SerializerProvider p)
public void setDeserializerProvider(DeserializerProvider p)
public SerializationConfig getSerializationConfig()
public void setSerializationConfig(SerializationConfig cfg)
public void configure(SerializationConfig.Feature f,
boolean state)
public DeserializationConfig getDeserializationConfig()
public void setDeserializationConfig(DeserializationConfig cfg)
public void configure(DeserializationConfig.Feature f,
boolean state)
public JsonFactory getJsonFactory()
public <T> T readValue(JsonParser jp,
java.lang.Class<T> valueType)
throws java.io.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 ObjectCodecjava.io.IOException
JsonParseException
JsonMappingException
public <T> T readValue(JsonParser jp,
TypeReference<?> valueTypeRef)
throws java.io.IOException,
JsonParseException,
JsonMappingException
readValue in class ObjectCodecjava.io.IOException
JsonParseException
JsonMappingException
public <T> T readValue(JsonParser jp,
JavaType valueType)
throws java.io.IOException,
JsonParseException,
JsonMappingException
TypeFactory.
readValue in class ObjectCodecjava.io.IOException
JsonParseException
JsonMappingException
public JsonNode readTree(JsonParser jp)
throws java.io.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 ObjectCodecjava.io.IOException
JsonProcessingException
public void writeValue(JsonGenerator jgen,
java.lang.Object value)
throws java.io.IOException,
JsonGenerationException,
JsonMappingException
JsonGenerator.
writeValue in class ObjectCodecjava.io.IOException
JsonGenerationException
JsonMappingException
public void writeTree(JsonGenerator jgen,
JsonNode rootNode)
throws java.io.IOException,
JsonProcessingException
writeTree in class ObjectCodecjava.io.IOException
JsonProcessingExceptionpublic boolean canSerialize(java.lang.Class<?> type)
public boolean canDeserialize(JavaType type)
public <T> T readValue(java.io.File src,
java.lang.Class<T> valueType)
throws java.io.IOException,
JsonParseException,
JsonMappingException
java.io.IOException
JsonParseException
JsonMappingException
public <T> T readValue(java.io.File src,
TypeReference valueTypeRef)
throws java.io.IOException,
JsonParseException,
JsonMappingException
java.io.IOException
JsonParseException
JsonMappingException
public <T> T readValue(java.io.File src,
JavaType valueType)
throws java.io.IOException,
JsonParseException,
JsonMappingException
java.io.IOException
JsonParseException
JsonMappingException
public <T> T readValue(java.net.URL src,
java.lang.Class<T> valueType)
throws java.io.IOException,
JsonParseException,
JsonMappingException
java.io.IOException
JsonParseException
JsonMappingException
public <T> T readValue(java.net.URL src,
TypeReference valueTypeRef)
throws java.io.IOException,
JsonParseException,
JsonMappingException
java.io.IOException
JsonParseException
JsonMappingException
public <T> T readValue(java.net.URL src,
JavaType valueType)
throws java.io.IOException,
JsonParseException,
JsonMappingException
java.io.IOException
JsonParseException
JsonMappingException
public <T> T readValue(java.lang.String content,
java.lang.Class<T> valueType)
throws java.io.IOException,
JsonParseException,
JsonMappingException
java.io.IOException
JsonParseException
JsonMappingException
public <T> T readValue(java.lang.String content,
TypeReference valueTypeRef)
throws java.io.IOException,
JsonParseException,
JsonMappingException
java.io.IOException
JsonParseException
JsonMappingException
public <T> T readValue(java.lang.String content,
JavaType valueType)
throws java.io.IOException,
JsonParseException,
JsonMappingException
java.io.IOException
JsonParseException
JsonMappingException
public <T> T readValue(java.io.Reader src,
java.lang.Class<T> valueType)
throws java.io.IOException,
JsonParseException,
JsonMappingException
java.io.IOException
JsonParseException
JsonMappingException
public <T> T readValue(java.io.Reader src,
TypeReference valueTypeRef)
throws java.io.IOException,
JsonParseException,
JsonMappingException
java.io.IOException
JsonParseException
JsonMappingException
public <T> T readValue(java.io.Reader src,
JavaType valueType)
throws java.io.IOException,
JsonParseException,
JsonMappingException
java.io.IOException
JsonParseException
JsonMappingException
public <T> T readValue(java.io.InputStream src,
java.lang.Class<T> valueType)
throws java.io.IOException,
JsonParseException,
JsonMappingException
java.io.IOException
JsonParseException
JsonMappingException
public <T> T readValue(java.io.InputStream src,
TypeReference valueTypeRef)
throws java.io.IOException,
JsonParseException,
JsonMappingException
java.io.IOException
JsonParseException
JsonMappingException
public <T> T readValue(java.io.InputStream src,
JavaType valueType)
throws java.io.IOException,
JsonParseException,
JsonMappingException
java.io.IOException
JsonParseException
JsonMappingException
public <T> T readValue(byte[] src,
int offset,
int len,
java.lang.Class<T> valueType)
throws java.io.IOException,
JsonParseException,
JsonMappingException
java.io.IOException
JsonParseException
JsonMappingException
public <T> T readValue(byte[] src,
int offset,
int len,
TypeReference valueTypeRef)
throws java.io.IOException,
JsonParseException,
JsonMappingException
java.io.IOException
JsonParseException
JsonMappingException
public <T> T readValue(byte[] src,
int offset,
int len,
JavaType valueType)
throws java.io.IOException,
JsonParseException,
JsonMappingException
java.io.IOException
JsonParseException
JsonMappingException
public void writeValue(java.io.File resultFile,
java.lang.Object value)
throws java.io.IOException,
JsonGenerationException,
JsonMappingException
java.io.IOException
JsonGenerationException
JsonMappingException
public void writeValue(java.io.OutputStream out,
java.lang.Object value)
throws java.io.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).
java.io.IOException
JsonGenerationException
JsonMappingException
public void writeValue(java.io.Writer w,
java.lang.Object value)
throws java.io.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).
java.io.IOException
JsonGenerationException
JsonMappingException
protected final void _configAndWriteValue(JsonGenerator jgen,
java.lang.Object value)
throws java.io.IOException,
JsonGenerationException,
JsonMappingException
java.io.IOException
JsonGenerationException
JsonMappingException
protected java.lang.Object _readValue(JsonParser jp,
JavaType valueType)
throws java.io.IOException,
JsonParseException,
JsonMappingException
java.io.IOException
JsonParseException
JsonMappingException
protected java.lang.Object _readMapAndClose(JsonParser jp,
JavaType valueType)
throws java.io.IOException,
JsonParseException,
JsonMappingException
java.io.IOException
JsonParseException
JsonMappingException
protected JsonToken _initForReading(JsonParser jp)
throws java.io.IOException,
JsonParseException,
JsonMappingException
java.io.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<java.lang.Object> _findRootDeserializer(JavaType valueType)
throws JsonMappingException
JsonMappingExceptionprotected DeserializationContext _createDeserializationContext(JsonParser jp)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||