|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.codehaus.jackson.map.ObjectWriter
public class ObjectWriter
Builder object that can be used for per-serialization configuration of
serialization parameters, such as JSON View and root type to use.
Uses "fluid" (aka builder) pattern so that instances are immutable
(and thus fully thread-safe); new instances are constructed for
different configurations.
Instances are initially constructed by ObjectMapper
, and can
be similarly reused.
Field Summary | |
---|---|
protected SerializationConfig |
_config
General serialization configuration settings |
protected TypeResolverBuilder<?> |
_defaultTyper
|
protected JsonFactory |
_jsonFactory
Factory used for constructing JsonGenerator s |
protected SerializerProvider |
_provider
|
protected JavaType |
_rootType
Specified root serialization type to use; can be same as runtime type, but usually one of its super types |
protected Class<?> |
_serializationView
View to use for serialization |
protected SerializerFactory |
_serializerFactory
|
protected VisibilityChecker<?> |
_visibilityChecker
|
Constructor Summary | |
---|---|
protected |
ObjectWriter(ObjectMapper mapper,
Class<?> view,
JavaType rootType)
Constructor used by ObjectMapper for initial instantiation |
protected |
ObjectWriter(ObjectWriter base,
SerializationConfig config,
Class<?> view,
JavaType rootType)
Copy constructor used for building variations. |
Method Summary | |
---|---|
protected void |
_configAndWriteValue(JsonGenerator jgen,
Object value)
Method called to configure the generator as necessary and then call write functionality |
boolean |
canSerialize(Class<?> type)
|
ObjectWriter |
withType(Class<?> rootType)
|
ObjectWriter |
withType(JavaType rootType)
|
ObjectWriter |
withView(Class<?> view)
|
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(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. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected final SerializationConfig _config
protected final SerializerProvider _provider
protected final SerializerFactory _serializerFactory
protected final JsonFactory _jsonFactory
JsonGenerator
s
protected TypeResolverBuilder<?> _defaultTyper
protected VisibilityChecker<?> _visibilityChecker
protected final Class<?> _serializationView
protected final JavaType _rootType
Constructor Detail |
---|
protected ObjectWriter(ObjectMapper mapper, Class<?> view, JavaType rootType)
ObjectMapper
for initial instantiation
protected ObjectWriter(ObjectWriter base, SerializationConfig config, Class<?> view, JavaType rootType)
Method Detail |
---|
public ObjectWriter withView(Class<?> view)
public ObjectWriter withType(JavaType rootType)
public ObjectWriter withType(Class<?> rootType)
public void writeValue(JsonGenerator jgen, Object value) throws IOException, JsonGenerationException, JsonMappingException
JsonGenerator
.
IOException
JsonGenerationException
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 boolean canSerialize(Class<?> type)
protected final void _configAndWriteValue(JsonGenerator jgen, Object value) throws IOException, JsonGenerationException, JsonMappingException
IOException
JsonGenerationException
JsonMappingException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |