|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.fasterxml.jackson.databind.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.
(and thus fully thread-safe with no external synchronization);
new instances are constructed for different configurations.
Instances are initially constructed by ObjectMapper
and can be
reused in completely thread-safe manner with no explicit synchronization
Field Summary | |
---|---|
protected SerializationConfig |
_config
General serialization configuration settings |
protected com.fasterxml.jackson.core.JsonFactory |
_jsonFactory
Factory used for constructing JsonGenerator s |
protected com.fasterxml.jackson.core.PrettyPrinter |
_prettyPrinter
To allow for dynamic enabling/disabling of pretty printing, pretty printer can be optionally configured for writer as well |
protected JavaType |
_rootType
Specified root serialization type to use; can be same as runtime type, but usually one of its super types |
protected com.fasterxml.jackson.core.FormatSchema |
_schema
When using data format that uses a schema, schema is passed to generator. |
protected SerializerFactory |
_serializerFactory
|
protected DefaultSerializerProvider |
_serializerProvider
|
protected static com.fasterxml.jackson.core.PrettyPrinter |
NULL_PRETTY_PRINTER
We need to keep track of explicit disabling of pretty printing; easiest to do by a token value. |
Constructor Summary | |
---|---|
protected |
ObjectWriter(ObjectMapper mapper,
SerializationConfig config)
Alternative constructor for initial instantiation. |
protected |
ObjectWriter(ObjectMapper mapper,
SerializationConfig config,
com.fasterxml.jackson.core.FormatSchema s)
Alternative constructor for initial instantiation. |
protected |
ObjectWriter(ObjectMapper mapper,
SerializationConfig config,
JavaType rootType,
com.fasterxml.jackson.core.PrettyPrinter pp)
Constructor used by ObjectMapper for initial instantiation |
protected |
ObjectWriter(ObjectWriter base,
SerializationConfig config)
Copy constructor used for building variations. |
protected |
ObjectWriter(ObjectWriter base,
SerializationConfig config,
JavaType rootType,
com.fasterxml.jackson.core.PrettyPrinter pp,
com.fasterxml.jackson.core.FormatSchema s)
Copy constructor used for building variations. |
Method Summary | |
---|---|
protected void |
_configAndWriteValue(com.fasterxml.jackson.core.JsonGenerator jgen,
Object value)
Method called to configure the generator as necessary and then call write functionality |
protected DefaultSerializerProvider |
_serializerProvider(SerializationConfig config)
Overridable helper method used for constructing SerializerProvider to use for serialization. |
boolean |
canSerialize(Class<?> type)
|
com.fasterxml.jackson.core.JsonFactory |
getJsonFactory()
|
TypeFactory |
getTypeFactory()
|
boolean |
isEnabled(com.fasterxml.jackson.core.JsonParser.Feature f)
|
boolean |
isEnabled(MapperFeature f)
|
boolean |
isEnabled(SerializationFeature f)
|
com.fasterxml.jackson.core.Version |
version()
Method that will return version information stored in and read from jar that contains this class. |
ObjectWriter |
with(DateFormat df)
Fluent factory method that will construct a new writer instance that will use specified date format for serializing dates; or if null passed, one that will serialize dates as numeric timestamps. |
ObjectWriter |
with(FilterProvider filterProvider)
Method that will construct a new instance that uses specified provider for resolving filter instances by id. |
ObjectWriter |
with(Locale l)
|
ObjectWriter |
with(com.fasterxml.jackson.core.PrettyPrinter pp)
Method that will construct a new instance that will use specified pretty printer (or, if null, will not do any pretty-printing) |
ObjectWriter |
with(SerializationFeature feature)
Method for constructing a new instance that is configured with specified feature enabled. |
ObjectWriter |
with(SerializationFeature first,
SerializationFeature... other)
Method for constructing a new instance that is configured with specified features enabled. |
ObjectWriter |
with(TimeZone tz)
|
ObjectWriter |
withDefaultPrettyPrinter()
Method that will construct a new instance that will use the default pretty printer for serialization. |
ObjectWriter |
withFeatures(SerializationFeature... features)
Method for constructing a new instance that is configured with specified features enabled. |
ObjectWriter |
without(SerializationFeature feature)
Method for constructing a new instance that is configured with specified feature enabled. |
ObjectWriter |
without(SerializationFeature first,
SerializationFeature... other)
Method for constructing a new instance that is configured with specified features enabled. |
ObjectWriter |
withoutFeatures(SerializationFeature... features)
Method for constructing a new instance that is configured with specified features enabled. |
ObjectWriter |
withRootName(String rootName)
Method for constructing a new instance with configuration that specifies what root name to use for "root element wrapping". |
ObjectWriter |
withSchema(com.fasterxml.jackson.core.FormatSchema schema)
Method that will construct a new instance that uses specific format schema for serialization. |
ObjectWriter |
withType(Class<?> rootType)
Method that will construct a new instance that uses specific type as the root type for serialization, instead of runtime dynamic type of the root object itself. |
ObjectWriter |
withType(JavaType rootType)
Method that will construct a new instance that uses specific type as the root type for serialization, instead of runtime dynamic type of the root object itself. |
ObjectWriter |
withType(com.fasterxml.jackson.core.type.TypeReference<?> rootType)
|
ObjectWriter |
withView(Class<?> view)
Method that will construct a new instance that uses specified serialization view for serialization (with null basically disables view processing) |
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(com.fasterxml.jackson.core.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 static final com.fasterxml.jackson.core.PrettyPrinter NULL_PRETTY_PRINTER
protected final SerializationConfig _config
protected final DefaultSerializerProvider _serializerProvider
protected final SerializerFactory _serializerFactory
protected final com.fasterxml.jackson.core.JsonFactory _jsonFactory
JsonGenerator
s
protected final JavaType _rootType
protected final com.fasterxml.jackson.core.PrettyPrinter _prettyPrinter
protected final com.fasterxml.jackson.core.FormatSchema _schema
Constructor Detail |
---|
protected ObjectWriter(ObjectMapper mapper, SerializationConfig config, JavaType rootType, com.fasterxml.jackson.core.PrettyPrinter pp)
ObjectMapper
for initial instantiation
protected ObjectWriter(ObjectMapper mapper, SerializationConfig config)
protected ObjectWriter(ObjectMapper mapper, SerializationConfig config, com.fasterxml.jackson.core.FormatSchema s)
protected ObjectWriter(ObjectWriter base, SerializationConfig config, JavaType rootType, com.fasterxml.jackson.core.PrettyPrinter pp, com.fasterxml.jackson.core.FormatSchema s)
protected ObjectWriter(ObjectWriter base, SerializationConfig config)
Method Detail |
---|
public com.fasterxml.jackson.core.Version version()
version
in interface com.fasterxml.jackson.core.Versioned
public ObjectWriter with(SerializationFeature feature)
public ObjectWriter with(SerializationFeature first, SerializationFeature... other)
public ObjectWriter withFeatures(SerializationFeature... features)
public ObjectWriter without(SerializationFeature feature)
public ObjectWriter without(SerializationFeature first, SerializationFeature... other)
public ObjectWriter withoutFeatures(SerializationFeature... features)
public ObjectWriter with(DateFormat df)
Note that the method does NOT change state of this reader, but rather construct and returns a newly configured instance.
public ObjectWriter withDefaultPrettyPrinter()
public ObjectWriter with(FilterProvider filterProvider)
public ObjectWriter with(com.fasterxml.jackson.core.PrettyPrinter pp)
public ObjectWriter withRootName(String rootName)
SerializationConfig.withRootName(String)
for details.
Note that method does NOT change state of this reader, but rather construct and returns a newly configured instance.
public ObjectWriter withSchema(com.fasterxml.jackson.core.FormatSchema schema)
Note that method does NOT change state of this reader, but rather construct and returns a newly configured instance.
public ObjectWriter withType(JavaType rootType)
Note that method does NOT change state of this reader, but rather construct and returns a newly configured instance.
public ObjectWriter withType(Class<?> rootType)
public ObjectWriter withType(com.fasterxml.jackson.core.type.TypeReference<?> rootType)
public ObjectWriter withView(Class<?> view)
Note that the method does NOT change state of this reader, but rather construct and returns a newly configured instance.
public ObjectWriter with(Locale l)
public ObjectWriter with(TimeZone tz)
public boolean isEnabled(SerializationFeature f)
public boolean isEnabled(MapperFeature f)
public boolean isEnabled(com.fasterxml.jackson.core.JsonParser.Feature f)
public com.fasterxml.jackson.core.JsonFactory getJsonFactory()
public TypeFactory getTypeFactory()
public void writeValue(com.fasterxml.jackson.core.JsonGenerator jgen, Object value) throws IOException, com.fasterxml.jackson.core.JsonGenerationException, JsonMappingException
JsonGenerator
.
IOException
com.fasterxml.jackson.core.JsonGenerationException
JsonMappingException
public void writeValue(File resultFile, Object value) throws IOException, com.fasterxml.jackson.core.JsonGenerationException, JsonMappingException
IOException
com.fasterxml.jackson.core.JsonGenerationException
JsonMappingException
public void writeValue(OutputStream out, Object value) throws IOException, com.fasterxml.jackson.core.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
com.fasterxml.jackson.core.JsonGenerationException
JsonMappingException
public void writeValue(Writer w, Object value) throws IOException, com.fasterxml.jackson.core.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
com.fasterxml.jackson.core.JsonGenerationException
JsonMappingException
public String writeValueAsString(Object value) throws IOException, com.fasterxml.jackson.core.JsonGenerationException, JsonMappingException
writeValue(Writer,Object)
with StringWriter
and constructing String, but more efficient.
IOException
com.fasterxml.jackson.core.JsonGenerationException
JsonMappingException
public byte[] writeValueAsBytes(Object value) throws IOException, com.fasterxml.jackson.core.JsonGenerationException, JsonMappingException
writeValue(Writer,Object)
with ByteArrayOutputStream
and getting bytes, but more efficient.
Encoding used will be UTF-8.
IOException
com.fasterxml.jackson.core.JsonGenerationException
JsonMappingException
public boolean canSerialize(Class<?> type)
protected DefaultSerializerProvider _serializerProvider(SerializationConfig config)
SerializerProvider
to use for serialization.
protected final void _configAndWriteValue(com.fasterxml.jackson.core.JsonGenerator jgen, Object value) throws IOException, com.fasterxml.jackson.core.JsonGenerationException, JsonMappingException
IOException
com.fasterxml.jackson.core.JsonGenerationException
JsonMappingException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |