Top Description Inners Fields Constructors Methods
com.fasterxml.jackson.databind

public Class ObjectWriter

extends Object
implements Versioned, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, com.fasterxml.jackson.core.Versioned
Imports
java.io.*, java.text.*, java.util.Locale, .Map, .TimeZone, java.util.concurrent.atomic.AtomicReference, com.fasterxml.jackson.core.*, com.fasterxml.jackson.core.exc.StreamWriteException, com.fasterxml.jackson.core.io.CharacterEscapes, .SegmentedStringWriter, .SerializedString, com.fasterxml.jackson.core.type.TypeReference, com.fasterxml.jackson.core.util.*, com.fasterxml.jackson.databind.cfg.ContextAttributes, .DatatypeFeature, com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitorWrapper, com.fasterxml.jackson.databind.jsontype.TypeSerializer, com.fasterxml.jackson.databind.ser.*, com.fasterxml.jackson.databind.ser.impl.TypeWrappedSerializer, com.fasterxml.jackson.databind.type.TypeFactory, com.fasterxml.jackson.databind.util.ClassUtil

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

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
ObjectWriter.GeneratorSettings

Helper class used for containing settings specifically related to (re)configuring JsonGenerator constructed for writing output.

public static class
ObjectWriter.Prefetch

As a minor optimization, we will make an effort to pre-fetch a serializer, or at least relevant TypeSerializer, if given enough information.

Field Summary

Modifier and TypeField and Description
protected final SerializationConfig
_config

General serialization configuration settings

protected final JsonFactory
_generatorFactory

Factory used for constructing JsonGenerators

protected final ObjectWriter.GeneratorSettings
_generatorSettings

Container for settings that need to be passed to JsonGenerator constructed for serializing values.

protected final ObjectWriter.Prefetch
_prefetch

We may pre-fetch serializer if root type is known (has been explicitly declared), and if so, reuse it afterwards.

protected final SerializerFactory
protected final DefaultSerializerProvider
protected static final PrettyPrinter
NULL_PRETTY_PRINTER

We need to keep track of explicit disabling of pretty printing; easiest to do by a token value.

private static final long

Constructor Summary

AccessConstructor and Description
protected
ObjectWriter(ObjectMapper mapper, SerializationConfig config, JavaType rootType, PrettyPrinter pp)

Constructor used by ObjectMapper for initial instantiation

protected
ObjectWriter(ObjectMapper mapper, SerializationConfig config)

Alternative constructor for initial instantiation by ObjectMapper

protected
ObjectWriter(ObjectMapper mapper, SerializationConfig config, FormatSchema s)

Alternative constructor for initial instantiation by ObjectMapper

protected
ObjectWriter(ObjectWriter base, SerializationConfig config, ObjectWriter.GeneratorSettings genSettings, ObjectWriter.Prefetch prefetch)

Copy constructor used for building variations.

protected
ObjectWriter(ObjectWriter base, SerializationConfig config)

Copy constructor used for building variations.

protected

Method Summary

Modifier and TypeMethod and Description
protected final void
_assertNotNull(String paramName, Object src)

protected final JsonGenerator
_configureGenerator(JsonGenerator gen)

Helper method called to set or override settings of passed-in JsonGenerator

protected ObjectWriter
_new(ObjectWriter base, JsonFactory f)

Overridable factory method called by various "withXxx()" methods

protected ObjectWriter
_new(ObjectWriter base, SerializationConfig config)

Overridable factory method called by various "withXxx()" methods

protected ObjectWriter
_new(ObjectWriter.GeneratorSettings genSettings, ObjectWriter.Prefetch prefetch)

Overridable factory method called by various "withXxx()" methods.

protected SequenceWriter
_newSequenceWriter(boolean wrapInArray, JsonGenerator gen, boolean managedInput)

Overridable factory method called by writeValues(OutputStream) method (and its various overrides), and initializes it as necessary.

protected DefaultSerializerProvider
_serializerProvider()

Overridable helper method used for constructing SerializerProvider to use for serialization.

protected void
private final void
_writeCloseable(JsonGenerator gen, Object value)

Helper method used when value to serialize is Closeable and its close() method is to be called right after serialization has been called

protected final void
_writeValueAndClose(JsonGenerator gen, Object value)

Method called to configure the generator as necessary and then call write functionality

public void
acceptJsonFormatVisitor(JavaType
Type to generate schema for (possibly with generic signature)
type
,
JsonFormatVisitorWrapper visitor)

Method for visiting type hierarchy for given type, using specified visitor.

public void
public boolean
canSerialize(Class<?> type)
Deprecated Since 2.18 use discouraged; method to be removed from Jackson 3.0

Method that can be called to check whether ObjectWriter thinks it could serialize an instance of given Class.

public boolean
canSerialize(Class<?> type, AtomicReference<Throwable> cause)
Deprecated Since 2.18 use discouraged; method to be removed from Jackson 3.0

Method for checking whether instances of given type can be serialized, and optionally why (as per Throwable returned).

public JsonGenerator
createGenerator(OutputStream out)

Factory method for constructing properly initialized JsonGenerator to write content using specified OutputStream.

public JsonGenerator
createGenerator(OutputStream out, JsonEncoding enc)

Factory method for constructing properly initialized JsonGenerator to write content using specified OutputStream and encoding.

public JsonGenerator
createGenerator(Writer w)

Factory method for constructing properly initialized JsonGenerator to write content using specified Writer.

public JsonGenerator
createGenerator(File outputFile, JsonEncoding enc)

Factory method for constructing properly initialized JsonGenerator to write content to specified File, using specified encoding.

public JsonGenerator
createGenerator(DataOutput out)

Factory method for constructing properly initialized JsonGenerator to write content using specified DataOutput.

public ObjectWriter
forType(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.

public ObjectWriter
forType(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.

public ObjectWriter
forType(TypeReference<?> 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.

public ContextAttributes
public SerializationConfig
public JsonFactory
public TypeFactory
public boolean
hasPrefetchedSerializer()

Diagnostics method that can be called to check whether this writer has pre-fetched serializer to use: pre-fetching improves performance when writer instances are reused as it avoids a per-call serializer lookup.

public boolean
public boolean
public boolean
public boolean
public boolean
public boolean
public Version
version()

Implements com.fasterxml.jackson.core.Versioned.version.

Method that will return version information stored in and read from jar that contains this class.

public ObjectWriter
with(SerializationFeature feature)

Method for constructing a new instance that is configured with specified feature enabled.

public ObjectWriter
with(SerializationFeature first, SerializationFeature... other)

Method for constructing a new instance that is configured with specified features enabled.

public ObjectWriter
with(DatatypeFeature feature)

Method for constructing a new instance that is configured with specified feature enabled.

public ObjectWriter
public ObjectWriter
public ObjectWriter
public 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.

public ObjectWriter
with(FilterProvider filterProvider)

Method that will construct a new instance that uses specified provider for resolving filter instances by id.

public ObjectWriter
with(PrettyPrinter pp)

Method that will construct a new instance that will use specified pretty printer (or, if null, will not do any pretty-printing)

public ObjectWriter
with(FormatSchema schema)

Method that will construct a new instance that uses specific format schema for serialization.

public ObjectWriter
public ObjectWriter
public ObjectWriter
with(Base64Variant b64variant)

Method that will construct a new instance that uses specified default Base64Variant for base64 encoding

public ObjectWriter
public ObjectWriter
public ObjectWriter
public ObjectWriter
public ObjectWriter
withAttributes(Map<?, ?> attrs)

Mutant factory method that allows construction of a new writer instance that uses specified set of default attribute values.

public ObjectWriter
withDefaultPrettyPrinter()

Method that will construct a new instance that will use the default pretty printer for serialization.

public ObjectWriter
withFeatures(SerializationFeature... features)

Method for constructing a new instance that is configured with specified features enabled.

public ObjectWriter
withFeatures(DatatypeFeature... features)

Method for constructing a new instance that is configured with specified features enabled.

public ObjectWriter
public ObjectWriter
public ObjectWriter
without(SerializationFeature feature)

Method for constructing a new instance that is configured with specified feature disabled.

public ObjectWriter
without(SerializationFeature first, SerializationFeature... other)

Method for constructing a new instance that is configured with specified features disabled.

public ObjectWriter
without(DatatypeFeature feature)

Method for constructing a new instance that is configured with specified feature disabled.

public ObjectWriter
public ObjectWriter
public ObjectWriter
public ObjectWriter
public ObjectWriter
withoutFeatures(SerializationFeature... features)

Method for constructing a new instance that is configured with specified features disabled.

public ObjectWriter
withoutFeatures(DatatypeFeature... features)

Method for constructing a new instance that is configured with specified features disabled.

public ObjectWriter
public ObjectWriter
public ObjectWriter
withoutRootName()

Convenience method that is same as calling: withRootName("") which will forcibly prevent use of root name wrapping when writing values with this ObjectWriter.

public ObjectWriter
withRootName(String
Root name to use, if non-empty; `null` for "use defaults", and empty String ("") for "do NOT add root wrapper"
rootName
)

Method for constructing a new instance with configuration that specifies what root name to use for "root element wrapping".

public ObjectWriter
public ObjectWriter
public ObjectWriter
public ObjectWriter
withSchema(FormatSchema schema)
Deprecated Since 2.5 use with(FormatSchema) instead

public ObjectWriter
withType(JavaType rootType)
Deprecated since 2.5 Use forType(JavaType) instead

public ObjectWriter
withType(Class<?> rootType)
Deprecated since 2.5 Use forType(Class) instead

public ObjectWriter
withType(TypeReference<?> rootType)
Deprecated since 2.5 Use forType(TypeReference) instead

public ObjectWriter
withView(Class<?> view)

Method that will construct a new instance that uses specified serialization view for serialization (with null basically disables view processing)

Note that the method does NOT change state of this reader, but rather construct and returns a newly configured instance.

public void
writeValue(JsonGenerator g, Object value)

Method that can be used to serialize any Java value as JSON output, using provided JsonGenerator.

public void
writeValue(File resultFile, Object value)

Method that can be used to serialize any Java value as JSON output, written to File provided.

public 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).

public void
writeValue(Writer w, Object value)

Method that can be used to serialize any Java value as JSON output, using Writer provided.

public void
public byte[]
writeValueAsBytes(Object value)

Method that can be used to serialize any Java value as a byte array.

public String
writeValueAsString(Object value)

Method that can be used to serialize any Java value as a String.

public SequenceWriter
writeValues(File
Target file to write value sequence to.
out
)

Method for creating a SequenceWriter to write a sequence of root values using configuration of this ObjectWriter.

public SequenceWriter
writeValues(JsonGenerator
Low-level generator caller has already constructed that will be used for actual writing of token stream.
g
)

Method for creating a SequenceWriter to write a sequence of root values using configuration of this ObjectWriter.

public SequenceWriter
writeValues(Writer
Target writer to use for writing the token stream
out
)

Method for creating a SequenceWriter to write a sequence of root values using configuration of this ObjectWriter.

public SequenceWriter
writeValues(OutputStream
Physical output stream to use for writing the token stream
out
)

Method for creating a SequenceWriter to write a sequence of root values using configuration of this ObjectWriter.

public SequenceWriter
public SequenceWriter
writeValuesAsArray(File
File to write token stream to
out
)

Method for creating a SequenceWriter to write an array of root-level values, using configuration of this ObjectWriter.

public SequenceWriter
writeValuesAsArray(JsonGenerator
Underlying generator to use for writing the token stream
gen
)

Method for creating a SequenceWriter to write an array of root-level values, using configuration of this ObjectWriter.

public SequenceWriter
writeValuesAsArray(Writer
Writer to use for writing the token stream
out
)

Method for creating a SequenceWriter to write an array of root-level values, using configuration of this ObjectWriter.

public SequenceWriter
writeValuesAsArray(OutputStream
Physical output stream to use for writing the token stream
out
)

Method for creating a SequenceWriter to write an array of root-level values, using configuration of this ObjectWriter.

public SequenceWriter
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait