Class ObjectWriter
- java.lang.Object
 - 
- com.fasterxml.jackson.databind.ObjectWriter
 
 
- 
- All Implemented Interfaces:
 Versioned,java.io.Serializable
public class ObjectWriter extends java.lang.Object implements Versioned, java.io.Serializable
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 byObjectMapperand can be reused in completely thread-safe manner with no explicit synchronization- See Also:
 - Serialized Form
 
 
- 
- 
Nested Class Summary
Nested Classes Modifier and Type Class Description static classObjectWriter.GeneratorSettingsHelper class used for containing settings specifically related to (re)configuringJsonGeneratorconstructed for writing output.static classObjectWriter.PrefetchAs a minor optimization, we will make an effort to pre-fetch a serializer, or at least relevantTypeSerializer, if given enough information. 
- 
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidacceptJsonFormatVisitor(JavaType type, JsonFormatVisitorWrapper visitor)Method for visiting type hierarchy for given type, using specified visitor.voidacceptJsonFormatVisitor(java.lang.Class<?> type, JsonFormatVisitorWrapper visitor)Since 2.6booleancanSerialize(java.lang.Class<?> type)booleancanSerialize(java.lang.Class<?> type, java.util.concurrent.atomic.AtomicReference<java.lang.Throwable> cause)Method for checking whether instances of given type can be serialized, and optionally why (as perThrowablereturned).JsonGeneratorcreateGenerator(java.io.DataOutput out)Factory method for constructing properly initializedJsonGeneratorto write content using specifiedDataOutput.JsonGeneratorcreateGenerator(java.io.File outputFile, JsonEncoding enc)Factory method for constructing properly initializedJsonGeneratorto write content to specifiedFile, using specified encoding.JsonGeneratorcreateGenerator(java.io.OutputStream out)Factory method for constructing properly initializedJsonGeneratorto write content using specifiedOutputStream.JsonGeneratorcreateGenerator(java.io.OutputStream out, JsonEncoding enc)Factory method for constructing properly initializedJsonGeneratorto write content using specifiedOutputStreamand encoding.JsonGeneratorcreateGenerator(java.io.Writer w)Factory method for constructing properly initializedJsonGeneratorto write content using specifiedWriter.ObjectWriterforType(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.ObjectWriterforType(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.ObjectWriterforType(java.lang.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.ContextAttributesgetAttributes()SerializationConfiggetConfig()JsonFactorygetFactory()TypeFactorygetTypeFactory()booleanhasPrefetchedSerializer()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.booleanisEnabled(JsonGenerator.Feature f)booleanisEnabled(JsonParser.Feature f)Deprecated.booleanisEnabled(StreamWriteFeature f)booleanisEnabled(DatatypeFeature f)booleanisEnabled(MapperFeature f)booleanisEnabled(SerializationFeature f)Versionversion()Method that will return version information stored in and read from jar that contains this class.ObjectWriterwith(Base64Variant b64variant)Method that will construct a new instance that uses specified defaultBase64Variantfor base64 encodingObjectWriterwith(FormatFeature feature)ObjectWriterwith(FormatSchema schema)Method that will construct a new instance that uses specific format schema for serialization.ObjectWriterwith(CharacterEscapes escapes)ObjectWriterwith(JsonFactory f)ObjectWriterwith(JsonGenerator.Feature feature)ObjectWriterwith(PrettyPrinter pp)Method that will construct a new instance that will use specified pretty printer (or, if null, will not do any pretty-printing)ObjectWriterwith(StreamWriteFeature feature)ObjectWriterwith(ContextAttributes attrs)ObjectWriterwith(DatatypeFeature feature)Method for constructing a new instance that is configured with specified feature enabled.ObjectWriterwith(FilterProvider filterProvider)Method that will construct a new instance that uses specified provider for resolving filter instances by id.ObjectWriterwith(SerializationFeature feature)Method for constructing a new instance that is configured with specified feature enabled.ObjectWriterwith(SerializationFeature first, SerializationFeature... other)Method for constructing a new instance that is configured with specified features enabled.ObjectWriterwith(java.text.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.ObjectWriterwith(java.util.Locale l)ObjectWriterwith(java.util.TimeZone tz)ObjectWriterwithAttribute(java.lang.Object key, java.lang.Object value)ObjectWriterwithAttributes(java.util.Map<?,?> attrs)Mutant factory method that allows construction of a new writer instance that uses specified set of default attribute values.ObjectWriterwithDefaultPrettyPrinter()Method that will construct a new instance that will use the default pretty printer for serialization.ObjectWriterwithFeatures(FormatFeature... features)ObjectWriterwithFeatures(JsonGenerator.Feature... features)ObjectWriterwithFeatures(DatatypeFeature... features)Method for constructing a new instance that is configured with specified features enabled.ObjectWriterwithFeatures(SerializationFeature... features)Method for constructing a new instance that is configured with specified features enabled.ObjectWriterwithout(FormatFeature feature)ObjectWriterwithout(JsonGenerator.Feature feature)ObjectWriterwithout(StreamWriteFeature feature)ObjectWriterwithout(DatatypeFeature feature)Method for constructing a new instance that is configured with specified feature disabled.ObjectWriterwithout(SerializationFeature feature)Method for constructing a new instance that is configured with specified feature disabled.ObjectWriterwithout(SerializationFeature first, SerializationFeature... other)Method for constructing a new instance that is configured with specified features disabled.ObjectWriterwithoutAttribute(java.lang.Object key)ObjectWriterwithoutFeatures(FormatFeature... features)ObjectWriterwithoutFeatures(JsonGenerator.Feature... features)ObjectWriterwithoutFeatures(DatatypeFeature... features)Method for constructing a new instance that is configured with specified features disabled.ObjectWriterwithoutFeatures(SerializationFeature... features)Method for constructing a new instance that is configured with specified features disabled.ObjectWriterwithoutRootName()Convenience method that is same as calling:withRootName("")which will forcibly prevent use of root name wrapping when writing values with thisObjectWriter.ObjectWriterwithRootName(PropertyName rootName)ObjectWriterwithRootName(java.lang.String rootName)Method for constructing a new instance with configuration that specifies what root name to use for "root element wrapping".ObjectWriterwithRootValueSeparator(SerializableString sep)ObjectWriterwithRootValueSeparator(java.lang.String sep)ObjectWriterwithSchema(FormatSchema schema)Deprecated.Since 2.5 usewith(FormatSchema)insteadObjectWriterwithType(TypeReference<?> rootType)Deprecated.since 2.5 UseforType(TypeReference)insteadObjectWriterwithType(JavaType rootType)Deprecated.since 2.5 UseforType(JavaType)insteadObjectWriterwithType(java.lang.Class<?> rootType)Deprecated.since 2.5 UseforType(Class)insteadObjectWriterwithView(java.lang.Class<?> view)Method that will construct a new instance that uses specified serialization view for serialization (with null basically disables view processing)voidwriteValue(JsonGenerator g, java.lang.Object value)Method that can be used to serialize any Java value as JSON output, using providedJsonGenerator.voidwriteValue(java.io.DataOutput out, java.lang.Object value)voidwriteValue(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.voidwriteValue(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 encodingJsonEncoding.UTF8).voidwriteValue(java.io.Writer w, java.lang.Object value)Method that can be used to serialize any Java value as JSON output, using Writer provided.byte[]writeValueAsBytes(java.lang.Object value)Method that can be used to serialize any Java value as a byte array.java.lang.StringwriteValueAsString(java.lang.Object value)Method that can be used to serialize any Java value as a String.SequenceWriterwriteValues(JsonGenerator g)Method for creating aSequenceWriterto write a sequence of root values using configuration of thisObjectWriter.SequenceWriterwriteValues(java.io.DataOutput out)SequenceWriterwriteValues(java.io.File out)Method for creating aSequenceWriterto write a sequence of root values using configuration of thisObjectWriter.SequenceWriterwriteValues(java.io.OutputStream out)Method for creating aSequenceWriterto write a sequence of root values using configuration of thisObjectWriter.SequenceWriterwriteValues(java.io.Writer out)Method for creating aSequenceWriterto write a sequence of root values using configuration of thisObjectWriter.SequenceWriterwriteValuesAsArray(JsonGenerator gen)Method for creating aSequenceWriterto write an array of root-level values, using configuration of thisObjectWriter.SequenceWriterwriteValuesAsArray(java.io.DataOutput out)SequenceWriterwriteValuesAsArray(java.io.File out)Method for creating aSequenceWriterto write an array of root-level values, using configuration of thisObjectWriter.SequenceWriterwriteValuesAsArray(java.io.OutputStream out)Method for creating aSequenceWriterto write an array of root-level values, using configuration of thisObjectWriter.SequenceWriterwriteValuesAsArray(java.io.Writer out)Method for creating aSequenceWriterto write an array of root-level values, using configuration of thisObjectWriter. 
 - 
 
- 
- 
Method Detail
- 
version
public Version version()
Method that will return version information stored in and read from jar that contains this class. 
- 
with
public ObjectWriter with(SerializationFeature feature)
Method for constructing a new instance that is configured with specified feature enabled. 
- 
with
public ObjectWriter with(SerializationFeature first, SerializationFeature... other)
Method for constructing a new instance that is configured with specified features enabled. 
- 
withFeatures
public ObjectWriter withFeatures(SerializationFeature... features)
Method for constructing a new instance that is configured with specified features enabled. 
- 
without
public ObjectWriter without(SerializationFeature feature)
Method for constructing a new instance that is configured with specified feature disabled. 
- 
without
public ObjectWriter without(SerializationFeature first, SerializationFeature... other)
Method for constructing a new instance that is configured with specified features disabled. 
- 
withoutFeatures
public ObjectWriter withoutFeatures(SerializationFeature... features)
Method for constructing a new instance that is configured with specified features disabled. 
- 
with
public ObjectWriter with(DatatypeFeature feature)
Method for constructing a new instance that is configured with specified feature enabled.- Since:
 - 2.14
 
 
- 
withFeatures
public ObjectWriter withFeatures(DatatypeFeature... features)
Method for constructing a new instance that is configured with specified features enabled.- Since:
 - 2.14
 
 
- 
without
public ObjectWriter without(DatatypeFeature feature)
Method for constructing a new instance that is configured with specified feature disabled.- Since:
 - 2.14
 
 
- 
withoutFeatures
public ObjectWriter withoutFeatures(DatatypeFeature... features)
Method for constructing a new instance that is configured with specified features disabled.- Since:
 - 2.14
 
 
- 
with
public ObjectWriter with(JsonGenerator.Feature feature)
- Since:
 - 2.5
 
 
- 
withFeatures
public ObjectWriter withFeatures(JsonGenerator.Feature... features)
- Since:
 - 2.5
 
 
- 
without
public ObjectWriter without(JsonGenerator.Feature feature)
- Since:
 - 2.5
 
 
- 
withoutFeatures
public ObjectWriter withoutFeatures(JsonGenerator.Feature... features)
- Since:
 - 2.5
 
 
- 
with
public ObjectWriter with(StreamWriteFeature feature)
- Since:
 - 2.11
 
 
- 
without
public ObjectWriter without(StreamWriteFeature feature)
- Since:
 - 2.11
 
 
- 
with
public ObjectWriter with(FormatFeature feature)
- Since:
 - 2.7
 
 
- 
withFeatures
public ObjectWriter withFeatures(FormatFeature... features)
- Since:
 - 2.7
 
 
- 
without
public ObjectWriter without(FormatFeature feature)
- Since:
 - 2.7
 
 
- 
withoutFeatures
public ObjectWriter withoutFeatures(FormatFeature... features)
- Since:
 - 2.7
 
 
- 
forType
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.Note that method does NOT change state of this reader, but rather construct and returns a newly configured instance.
- Since:
 - 2.5
 
 
- 
forType
public ObjectWriter forType(java.lang.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.- Since:
 - 2.5
 
 
- 
forType
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.- Since:
 - 2.5
 
 
- 
withType
@Deprecated public ObjectWriter withType(JavaType rootType)
Deprecated.since 2.5 UseforType(JavaType)instead 
- 
withType
@Deprecated public ObjectWriter withType(java.lang.Class<?> rootType)
Deprecated.since 2.5 UseforType(Class)instead 
- 
withType
@Deprecated public ObjectWriter withType(TypeReference<?> rootType)
Deprecated.since 2.5 UseforType(TypeReference)instead 
- 
with
public ObjectWriter with(java.text.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.Note that the method does NOT change state of this reader, but rather construct and returns a newly configured instance.
 
- 
withDefaultPrettyPrinter
public ObjectWriter withDefaultPrettyPrinter()
Method that will construct a new instance that will use the default pretty printer for serialization. 
- 
with
public ObjectWriter with(FilterProvider filterProvider)
Method that will construct a new instance that uses specified provider for resolving filter instances by id. 
- 
with
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) 
- 
withRootName
public ObjectWriter withRootName(java.lang.String rootName)
Method for constructing a new instance with configuration that specifies what root name to use for "root element wrapping". SeeMapperConfigBase.withRootName(String)for details.Note that method does NOT change state of this reader, but rather construct and returns a newly configured instance.
- Parameters:
 rootName- Root name to use, if non-empty; `null` for "use defaults", and empty String ("") for "do NOT add root wrapper"
 
- 
withRootName
public ObjectWriter withRootName(PropertyName rootName)
- Since:
 - 2.6
 
 
- 
withoutRootName
public ObjectWriter withoutRootName()
Convenience method that is same as calling:withRootName("")which will forcibly prevent use of root name wrapping when writing values with thisObjectWriter.- Since:
 - 2.6
 
 
- 
with
public ObjectWriter with(FormatSchema schema)
Method that will construct a new instance that uses specific format schema for serialization.Note that method does NOT change state of this reader, but rather construct and returns a newly configured instance.
 
- 
withSchema
@Deprecated public ObjectWriter withSchema(FormatSchema schema)
Deprecated.Since 2.5 usewith(FormatSchema)instead 
- 
withView
public ObjectWriter withView(java.lang.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.
 
- 
with
public ObjectWriter with(java.util.Locale l)
 
- 
with
public ObjectWriter with(java.util.TimeZone tz)
 
- 
with
public ObjectWriter with(Base64Variant b64variant)
Method that will construct a new instance that uses specified defaultBase64Variantfor base64 encoding- Since:
 - 2.1
 
 
- 
with
public ObjectWriter with(CharacterEscapes escapes)
- Since:
 - 2.3
 
 
- 
with
public ObjectWriter with(JsonFactory f)
- Since:
 - 2.3
 
 
- 
with
public ObjectWriter with(ContextAttributes attrs)
- Since:
 - 2.3
 
 
- 
withAttributes
public ObjectWriter withAttributes(java.util.Map<?,?> attrs)
Mutant factory method that allows construction of a new writer instance that uses specified set of default attribute values.- Since:
 - 2.3
 
 
- 
withAttribute
public ObjectWriter withAttribute(java.lang.Object key, java.lang.Object value)
- Since:
 - 2.3
 
 
- 
withoutAttribute
public ObjectWriter withoutAttribute(java.lang.Object key)
- Since:
 - 2.3
 
 
- 
withRootValueSeparator
public ObjectWriter withRootValueSeparator(java.lang.String sep)
- Since:
 - 2.5
 
 
- 
withRootValueSeparator
public ObjectWriter withRootValueSeparator(SerializableString sep)
- Since:
 - 2.5
 
 
- 
createGenerator
public JsonGenerator createGenerator(java.io.OutputStream out) throws java.io.IOException
Factory method for constructing properly initializedJsonGeneratorto write content using specifiedOutputStream. Generator is not managed (or "owned") by ObjectWriter: caller is responsible for properly closing it once content generation is complete.- Throws:
 java.io.IOException- Since:
 - 2.11
 
 
- 
createGenerator
public JsonGenerator createGenerator(java.io.OutputStream out, JsonEncoding enc) throws java.io.IOException
Factory method for constructing properly initializedJsonGeneratorto write content using specifiedOutputStreamand encoding. Generator is not managed (or "owned") by ObjectWriter: caller is responsible for properly closing it once content generation is complete.- Throws:
 java.io.IOException- Since:
 - 2.11
 
 
- 
createGenerator
public JsonGenerator createGenerator(java.io.Writer w) throws java.io.IOException
Factory method for constructing properly initializedJsonGeneratorto write content using specifiedWriter. Generator is not managed (or "owned") by ObjectWriter: caller is responsible for properly closing it once content generation is complete.- Throws:
 java.io.IOException- Since:
 - 2.11
 
 
- 
createGenerator
public JsonGenerator createGenerator(java.io.File outputFile, JsonEncoding enc) throws java.io.IOException
Factory method for constructing properly initializedJsonGeneratorto write content to specifiedFile, using specified encoding. Generator is not managed (or "owned") by ObjectWriter: caller is responsible for properly closing it once content generation is complete.- Throws:
 java.io.IOException- Since:
 - 2.11
 
 
- 
createGenerator
public JsonGenerator createGenerator(java.io.DataOutput out) throws java.io.IOException
Factory method for constructing properly initializedJsonGeneratorto write content using specifiedDataOutput. Generator is not managed (or "owned") by ObjectWriter: caller is responsible for properly closing it once content generation is complete.- Throws:
 java.io.IOException- Since:
 - 2.11
 
 
- 
writeValues
public SequenceWriter writeValues(java.io.File out) throws java.io.IOException
Method for creating aSequenceWriterto write a sequence of root values using configuration of thisObjectWriter. Sequence is not surrounded by JSON array; some backend types may not support writing of such sequences as root level. Resulting writer needs to beSequenceWriter.close()d after all values have been written to ensure closing of underlying generator and output stream.- Parameters:
 out- Target file to write value sequence to.- Throws:
 java.io.IOException- Since:
 - 2.5
 
 
- 
writeValues
public SequenceWriter writeValues(JsonGenerator g) throws java.io.IOException
Method for creating aSequenceWriterto write a sequence of root values using configuration of thisObjectWriter. Sequence is not surrounded by JSON array; some backend types may not support writing of such sequences as root level. Resulting writer needs to beSequenceWriter.close()d after all values have been written to ensure that all content gets flushed by the generator. However, since aJsonGeneratoris explicitly passed, it will NOT be closed whenSequenceWriter.close()is called.- Parameters:
 g- Low-level generator caller has already constructed that will be used for actual writing of token stream.- Throws:
 java.io.IOException- Since:
 - 2.5
 
 
- 
writeValues
public SequenceWriter writeValues(java.io.Writer out) throws java.io.IOException
Method for creating aSequenceWriterto write a sequence of root values using configuration of thisObjectWriter. Sequence is not surrounded by JSON array; some backend types may not support writing of such sequences as root level. Resulting writer needs to beSequenceWriter.close()d after all values have been written to ensure closing of underlying generator and output stream.- Parameters:
 out- Target writer to use for writing the token stream- Throws:
 java.io.IOException- Since:
 - 2.5
 
 
- 
writeValues
public SequenceWriter writeValues(java.io.OutputStream out) throws java.io.IOException
Method for creating aSequenceWriterto write a sequence of root values using configuration of thisObjectWriter. Sequence is not surrounded by JSON array; some backend types may not support writing of such sequences as root level. Resulting writer needs to beSequenceWriter.close()d after all values have been written to ensure closing of underlying generator and output stream.- Parameters:
 out- Physical output stream to use for writing the token stream- Throws:
 java.io.IOException- Since:
 - 2.5
 
 
- 
writeValues
public SequenceWriter writeValues(java.io.DataOutput out) throws java.io.IOException
- Throws:
 java.io.IOException- Since:
 - 2.8
 
 
- 
writeValuesAsArray
public SequenceWriter writeValuesAsArray(java.io.File out) throws java.io.IOException
Method for creating aSequenceWriterto write an array of root-level values, using configuration of thisObjectWriter. Resulting writer needs to beSequenceWriter.close()d after all values have been written to ensure closing of underlying generator and output stream.Note that the type to use with
forType(Class)needs to be type of individual values (elements) to write and NOT matching array orCollectiontype.- Parameters:
 out- File to write token stream to- Throws:
 java.io.IOException- Since:
 - 2.5
 
 
- 
writeValuesAsArray
public SequenceWriter writeValuesAsArray(JsonGenerator gen) throws java.io.IOException
Method for creating aSequenceWriterto write an array of root-level values, using configuration of thisObjectWriter. Resulting writer needs to beSequenceWriter.close()d after all values have been written to ensure that all content gets flushed by the generator. However, since aJsonGeneratoris explicitly passed, it will NOT be closed whenSequenceWriter.close()is called.Note that the type to use with
forType(Class)needs to be type of individual values (elements) to write and NOT matching array orCollectiontype.- Parameters:
 gen- Underlying generator to use for writing the token stream- Throws:
 java.io.IOException- Since:
 - 2.5
 
 
- 
writeValuesAsArray
public SequenceWriter writeValuesAsArray(java.io.Writer out) throws java.io.IOException
Method for creating aSequenceWriterto write an array of root-level values, using configuration of thisObjectWriter. Resulting writer needs to beSequenceWriter.close()d after all values have been written to ensure closing of underlying generator and output stream.Note that the type to use with
forType(Class)needs to be type of individual values (elements) to write and NOT matching array orCollectiontype.- Parameters:
 out- Writer to use for writing the token stream- Throws:
 java.io.IOException- Since:
 - 2.5
 
 
- 
writeValuesAsArray
public SequenceWriter writeValuesAsArray(java.io.OutputStream out) throws java.io.IOException
Method for creating aSequenceWriterto write an array of root-level values, using configuration of thisObjectWriter. Resulting writer needs to beSequenceWriter.close()d after all values have been written to ensure closing of underlying generator and output stream.Note that the type to use with
forType(Class)needs to be type of individual values (elements) to write and NOT matching array orCollectiontype.- Parameters:
 out- Physical output stream to use for writing the token stream- Throws:
 java.io.IOException- Since:
 - 2.5
 
 
- 
writeValuesAsArray
public SequenceWriter writeValuesAsArray(java.io.DataOutput out) throws java.io.IOException
- Throws:
 java.io.IOException- Since:
 - 2.8
 
 
- 
isEnabled
public boolean isEnabled(SerializationFeature f)
 
- 
isEnabled
public boolean isEnabled(MapperFeature f)
 
- 
isEnabled
public boolean isEnabled(DatatypeFeature f)
- Since:
 - 2.14
 
 
- 
isEnabled
@Deprecated public boolean isEnabled(JsonParser.Feature f)
Deprecated.- Since:
 - 2.9
 
 
- 
isEnabled
public boolean isEnabled(JsonGenerator.Feature f)
- Since:
 - 2.9
 
 
- 
isEnabled
public boolean isEnabled(StreamWriteFeature f)
- Since:
 - 2.11
 
 
- 
getConfig
public SerializationConfig getConfig()
- Since:
 - 2.2
 
 
- 
getFactory
public JsonFactory getFactory()
- Since:
 - 2.2
 
 
- 
getTypeFactory
public TypeFactory getTypeFactory()
 
- 
hasPrefetchedSerializer
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.- Since:
 - 2.2
 
 
- 
getAttributes
public ContextAttributes getAttributes()
- Since:
 - 2.3
 
 
- 
writeValue
public void writeValue(JsonGenerator g, java.lang.Object value) throws java.io.IOException
Method that can be used to serialize any Java value as JSON output, using providedJsonGenerator.Note that the given
JsonGeneratoris not closed; caller is expected to handle that as necessary.- Throws:
 java.io.IOException
 
- 
writeValue
public void writeValue(java.io.File resultFile, java.lang.Object value) throws java.io.IOException, StreamWriteException, DatabindExceptionMethod that can be used to serialize any Java value as JSON output, written to File provided.- Throws:
 java.io.IOExceptionStreamWriteExceptionDatabindException
 
- 
writeValue
public void writeValue(java.io.OutputStream out, java.lang.Object value) throws java.io.IOException, StreamWriteException, DatabindExceptionMethod that can be used to serialize any Java value as JSON output, using output stream provided (using encodingJsonEncoding.UTF8).Note: method does not close the underlying stream explicitly here; however,
JsonFactorythis mapper uses may choose to close the stream depending on its settings (by default, it will try to close it whenJsonGeneratorwe construct is closed).- Throws:
 java.io.IOExceptionStreamWriteExceptionDatabindException
 
- 
writeValue
public void writeValue(java.io.Writer w, java.lang.Object value) throws java.io.IOException, StreamWriteException, DatabindExceptionMethod that can be used to serialize any Java value as JSON output, using Writer provided.Note: method does not close the underlying stream explicitly here; however,
JsonFactorythis mapper uses may choose to close the stream depending on its settings (by default, it will try to close it whenJsonGeneratorwe construct is closed).- Throws:
 java.io.IOExceptionStreamWriteExceptionDatabindException
 
- 
writeValue
public void writeValue(java.io.DataOutput out, java.lang.Object value) throws java.io.IOException, StreamWriteException, DatabindException- Throws:
 java.io.IOExceptionStreamWriteExceptionDatabindException- Since:
 - 2.8
 
 
- 
writeValueAsString
public java.lang.String writeValueAsString(java.lang.Object value) throws JsonProcessingExceptionMethod that can be used to serialize any Java value as a String. Functionally equivalent to callingwriteValue(Writer,Object)withStringWriterand constructing String, but more efficient.Note: prior to version 2.1, throws clause included
IOException; 2.1 removed it.- Throws:
 JsonProcessingException
 
- 
writeValueAsBytes
public byte[] writeValueAsBytes(java.lang.Object value) throws JsonProcessingExceptionMethod that can be used to serialize any Java value as a byte array. Functionally equivalent to callingwriteValue(Writer,Object)withByteArrayOutputStreamand getting bytes, but more efficient. Encoding used will be UTF-8.Note: prior to version 2.1, throws clause included
IOException; 2.1 removed it.- Throws:
 JsonProcessingException
 
- 
acceptJsonFormatVisitor
public void acceptJsonFormatVisitor(JavaType type, JsonFormatVisitorWrapper visitor) throws JsonMappingException
Method for visiting type hierarchy for given type, using specified visitor. Visitation usesSerializerhierarchy and related propertiesThis method can be used for things like generating Json Schema instance for specified type.
- Parameters:
 type- Type to generate schema for (possibly with generic signature)- Throws:
 JsonMappingException- Since:
 - 2.2
 
 
- 
acceptJsonFormatVisitor
public void acceptJsonFormatVisitor(java.lang.Class<?> type, JsonFormatVisitorWrapper visitor) throws JsonMappingExceptionSince 2.6- Throws:
 JsonMappingException
 
- 
canSerialize
public boolean canSerialize(java.lang.Class<?> type)
 
- 
canSerialize
public boolean canSerialize(java.lang.Class<?> type, java.util.concurrent.atomic.AtomicReference<java.lang.Throwable> cause)Method for checking whether instances of given type can be serialized, and optionally why (as perThrowablereturned).- Since:
 - 2.3
 
 
 - 
 
 -