Top Description Inners Fields Constructors Methods
tools.jackson.databind

public Class ObjectWriter

extends Object
implements Versioned
Class Inheritance
All Implemented Interfaces
tools.jackson.core.Versioned
Imports
java.io.*, java.nio.file.Path, java.text.*, java.util.Locale, .Map, .TimeZone, tools.jackson.core.*, tools.jackson.core.exc.JacksonIOException, tools.jackson.core.io.CharacterEscapes, .SegmentedStringWriter, tools.jackson.core.type.TypeReference, tools.jackson.core.util.*, tools.jackson.databind.cfg.ContextAttributes, .DatatypeFeature, .GeneratorSettings, .SerializationContexts, tools.jackson.databind.jsonFormatVisitors.JsonFormatVisitorWrapper, tools.jackson.databind.jsontype.TypeSerializer, tools.jackson.databind.node.ArrayNode, .ObjectNode, tools.jackson.databind.ser.*, tools.jackson.databind.ser.impl.TypeWrappedSerializer, tools.jackson.databind.type.TypeFactory, tools.jackson.databind.util.ClassUtil, .TokenBuffer

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.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 TokenStreamFactory
_generatorFactory

Factory used for constructing JsonGenerators

protected final 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 SerializationContexts
_serializationContexts

Factory used for constructing per-call SerializationContexts.

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, GeneratorSettings genSettings, ObjectWriter.Prefetch prefetch)

Copy constructor used for building variations.

protected
ObjectWriter(ObjectWriter base, SerializationConfig config)

Copy constructor used for building variations.

Method Summary

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

protected final void
_configAndWriteValue(SerializationContextExt ctxt, JsonGenerator gen, Object value)

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

protected ObjectWriter
_new(ObjectWriter base, SerializationConfig config)

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

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

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

protected final SequenceWriter
_newSequenceWriter(SerializationContextExt ctxt, boolean wrapInArray, JsonGenerator gen, boolean managedInput)

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

protected final SerializationContextExt
_serializationContext()

Overridable helper method used for constructing SerializationContext 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

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 ArrayNode
public JsonGenerator
createGenerator(OutputStream target)

Factory method for constructing JsonGenerator that is properly wired to allow callbacks for serialization: basically constructs a ObjectWriteContext and then calls TokenStreamFactory#createGenerator(ObjectWriteContext, OutputStream).

public JsonGenerator
createGenerator(OutputStream target, JsonEncoding enc)

Factory method for constructing JsonGenerator that is properly wired to allow callbacks for serialization: basically constructs a ObjectWriteContext and then calls TokenStreamFactory#createGenerator(ObjectWriteContext, OutputStream, JsonEncoding).

public JsonGenerator
createGenerator(Writer target)

Factory method for constructing JsonGenerator that is properly wired to allow callbacks for serialization: basically constructs a ObjectWriteContext and then calls TokenStreamFactory#createGenerator(ObjectWriteContext, Writer).

public JsonGenerator
createGenerator(File target, JsonEncoding enc)

Factory method for constructing JsonGenerator that is properly wired to allow callbacks for serialization: basically constructs a ObjectWriteContext and then calls TokenStreamFactory#createGenerator(ObjectWriteContext, File, JsonEncoding).

public JsonGenerator
createGenerator(Path target, JsonEncoding enc)

Factory method for constructing JsonGenerator that is properly wired to allow callbacks for serialization: basically constructs a ObjectWriteContext and then calls TokenStreamFactory#createGenerator(ObjectWriteContext, Path, JsonEncoding).

public JsonGenerator
createGenerator(DataOutput target)

Factory method for constructing JsonGenerator that is properly wired to allow callbacks for serialization: basically constructs a ObjectWriteContext and then calls TokenStreamFactory#createGenerator(ObjectWriteContext, DataOutput).

public ObjectNode
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 TokenStreamFactory
public ContextAttributes
public SerializationConfig
public TypeFactory
getTypeFactory()
Deprecated Since 3.0 use 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 TypeFactory
public <
Actual node type; usually either basic JsonNode or tools.jackson.databind.node.ObjectNode
T extends JsonNode
>
T

Returns:

(non-null) Root node of the resulting content tree: in case of null value node for which JsonNode#isNull() returns true.
valueToTree
(Object
Java value to convert
fromValue
)

Method that will convert given Java value (usually bean) into its equivalent Tree model JsonNode representation.

public Version
version()

Implements tools.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
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

Returns:

ObjectWriter instance with specified default attributes (which is usually a newly constructed writer instance with otherwise identical settings)
with
(ContextAttributes
Default ContextAttributes to use with a writer
attrs
)

Mutant factory for overriding set of (default) attributes for ObjectWriter to use.

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
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
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 target, Object value)

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

public void
writeValue(Path target, Object value)

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

public void
writeValue(OutputStream target, 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 target, Object value)

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

public void
writeValue(DataOutput target, Object value)

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 TokenBuffer
writeValueIntoBuffer(Object value)

Convenience method that can be used to serialize any Java value into newly created TokenBuffer.

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

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

public SequenceWriter
writeValues(Path
Target path to write value sequence to.
target
)

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
target
)

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
target
)

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
target
)

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

public SequenceWriter
writeValuesAsArray(Path
Path to write token stream to
target
)

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
g
)

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
target
)

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
target
)

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