Class ObjectWriter
- java.lang.Object
-
- com.fasterxml.jackson.databind.ObjectWriter
-
- All Implemented Interfaces:
com.fasterxml.jackson.core.Versioned,Serializable
public class ObjectWriter extends Object implements com.fasterxml.jackson.core.Versioned, 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.
-
Field Summary
Fields Modifier and Type Field Description protected SerializationConfig_configGeneral serialization configuration settingsprotected com.fasterxml.jackson.core.JsonFactory_generatorFactoryFactory used for constructingJsonGeneratorsprotected ObjectWriter.GeneratorSettings_generatorSettingsContainer for settings that need to be passed toJsonGeneratorconstructed for serializing values.protected ObjectWriter.Prefetch_prefetchWe may pre-fetch serializer if root type is known (has been explicitly declared), and if so, reuse it afterwards.protected SerializerFactory_serializerFactoryprotected DefaultSerializerProvider_serializerProviderprotected static com.fasterxml.jackson.core.PrettyPrinterNULL_PRETTY_PRINTERWe need to keep track of explicit disabling of pretty printing; easiest to do by a token value.
-
Constructor Summary
Constructors Modifier Constructor Description protectedObjectWriter(ObjectMapper mapper, SerializationConfig config)Alternative constructor for initial instantiation byObjectMapperprotectedObjectWriter(ObjectMapper mapper, SerializationConfig config, com.fasterxml.jackson.core.FormatSchema s)Alternative constructor for initial instantiation byObjectMapperprotectedObjectWriter(ObjectMapper mapper, SerializationConfig config, JavaType rootType, com.fasterxml.jackson.core.PrettyPrinter pp)Constructor used byObjectMapperfor initial instantiationprotectedObjectWriter(ObjectWriter base, com.fasterxml.jackson.core.JsonFactory f)protectedObjectWriter(ObjectWriter base, SerializationConfig config)Copy constructor used for building variations.protectedObjectWriter(ObjectWriter base, SerializationConfig config, ObjectWriter.GeneratorSettings genSettings, ObjectWriter.Prefetch prefetch)Copy constructor used for building variations.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected void_assertNotNull(String paramName, Object src)protected void_configAndWriteValue(com.fasterxml.jackson.core.JsonGenerator gen, Object value)Method called to configure the generator as necessary and then call write functionalityprotected void_configureGenerator(com.fasterxml.jackson.core.JsonGenerator gen)Helper method called to set or override settings of passed-inJsonGeneratorprotected ObjectWriter_new(ObjectWriter.GeneratorSettings genSettings, ObjectWriter.Prefetch prefetch)Overridable factory method called by various "withXxx()" methods.protected ObjectWriter_new(ObjectWriter base, com.fasterxml.jackson.core.JsonFactory f)Overridable factory method called by various "withXxx()" methodsprotected ObjectWriter_new(ObjectWriter base, SerializationConfig config)Overridable factory method called by various "withXxx()" methodsprotected SequenceWriter_newSequenceWriter(boolean wrapInArray, com.fasterxml.jackson.core.JsonGenerator gen, boolean managedInput)Overridable factory method called bywriteValues(OutputStream)method (and its various overrides), and initializes it as necessary.protected DefaultSerializerProvider_serializerProvider()Overridable helper method used for constructingSerializerProviderto use for serialization.protected void_verifySchemaType(com.fasterxml.jackson.core.FormatSchema schema)voidacceptJsonFormatVisitor(JavaType type, JsonFormatVisitorWrapper visitor)Method for visiting type hierarchy for given type, using specified visitor.voidacceptJsonFormatVisitor(Class<?> type, JsonFormatVisitorWrapper visitor)Since 2.6booleancanSerialize(Class<?> type)booleancanSerialize(Class<?> type, AtomicReference<Throwable> cause)Method for checking whether instances of given type can be serialized, and optionally why (as perThrowablereturned).ObjectWriterforType(com.fasterxml.jackson.core.type.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(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()com.fasterxml.jackson.core.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(com.fasterxml.jackson.core.JsonGenerator.Feature f)booleanisEnabled(com.fasterxml.jackson.core.JsonParser.Feature f)Deprecated.booleanisEnabled(MapperFeature f)booleanisEnabled(SerializationFeature f)com.fasterxml.jackson.core.Versionversion()Method that will return version information stored in and read from jar that contains this class.ObjectWriterwith(com.fasterxml.jackson.core.Base64Variant b64variant)Method that will construct a new instance that uses specified defaultBase64Variantfor base64 encodingObjectWriterwith(com.fasterxml.jackson.core.FormatFeature feature)ObjectWriterwith(com.fasterxml.jackson.core.FormatSchema schema)Method that will construct a new instance that uses specific format schema for serialization.ObjectWriterwith(com.fasterxml.jackson.core.io.CharacterEscapes escapes)ObjectWriterwith(com.fasterxml.jackson.core.JsonFactory f)ObjectWriterwith(com.fasterxml.jackson.core.JsonGenerator.Feature feature)ObjectWriterwith(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)ObjectWriterwith(ContextAttributes attrs)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(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(Locale l)ObjectWriterwith(TimeZone tz)ObjectWriterwithAttribute(Object key, Object value)ObjectWriterwithAttributes(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(com.fasterxml.jackson.core.FormatFeature... features)ObjectWriterwithFeatures(com.fasterxml.jackson.core.JsonGenerator.Feature... features)ObjectWriterwithFeatures(SerializationFeature... features)Method for constructing a new instance that is configured with specified features enabled.ObjectWriterwithout(com.fasterxml.jackson.core.FormatFeature feature)ObjectWriterwithout(com.fasterxml.jackson.core.JsonGenerator.Feature feature)ObjectWriterwithout(SerializationFeature feature)Method for constructing a new instance that is configured with specified feature enabled.ObjectWriterwithout(SerializationFeature first, SerializationFeature... other)Method for constructing a new instance that is configured with specified features enabled.ObjectWriterwithoutAttribute(Object key)ObjectWriterwithoutFeatures(com.fasterxml.jackson.core.FormatFeature... features)ObjectWriterwithoutFeatures(com.fasterxml.jackson.core.JsonGenerator.Feature... features)ObjectWriterwithoutFeatures(SerializationFeature... features)Method for constructing a new instance that is configured with specified features enabled.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(String rootName)Method for constructing a new instance with configuration that specifies what root name to use for "root element wrapping".ObjectWriterwithRootValueSeparator(com.fasterxml.jackson.core.SerializableString sep)ObjectWriterwithRootValueSeparator(String sep)ObjectWriterwithSchema(com.fasterxml.jackson.core.FormatSchema schema)Deprecated.Since 2.5 usewith(FormatSchema)insteadObjectWriterwithType(com.fasterxml.jackson.core.type.TypeReference<?> rootType)Deprecated.since 2.5 UseforType(TypeReference)insteadObjectWriterwithType(JavaType rootType)Deprecated.since 2.5 UseforType(JavaType)insteadObjectWriterwithType(Class<?> rootType)Deprecated.since 2.5 UseforType(Class)insteadObjectWriterwithView(Class<?> view)Method that will construct a new instance that uses specified serialization view for serialization (with null basically disables view processing)voidwriteValue(com.fasterxml.jackson.core.JsonGenerator g, Object value)Method that can be used to serialize any Java value as JSON output, using providedJsonGenerator.voidwriteValue(DataOutput out, Object value)voidwriteValue(File resultFile, Object value)Method that can be used to serialize any Java value as JSON output, written to File provided.voidwriteValue(OutputStream out, Object value)Method that can be used to serialize any Java value as JSON output, using output stream provided (using encodingJsonEncoding.UTF8).voidwriteValue(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.StringwriteValueAsString(Object value)Method that can be used to serialize any Java value as a String.SequenceWriterwriteValues(com.fasterxml.jackson.core.JsonGenerator g)Method for creating aSequenceWriterto write a sequence of root values using configuration of thisObjectWriter.SequenceWriterwriteValues(DataOutput out)SequenceWriterwriteValues(File out)Method for creating aSequenceWriterto write a sequence of root values using configuration of thisObjectWriter.SequenceWriterwriteValues(OutputStream out)Method for creating aSequenceWriterto write a sequence of root values using configuration of thisObjectWriter.SequenceWriterwriteValues(Writer out)Method for creating aSequenceWriterto write a sequence of root values using configuration of thisObjectWriter.SequenceWriterwriteValuesAsArray(com.fasterxml.jackson.core.JsonGenerator gen)Method for creating aSequenceWriterto write an array of root-level values, using configuration of thisObjectWriter.SequenceWriterwriteValuesAsArray(DataOutput out)SequenceWriterwriteValuesAsArray(File out)Method for creating aSequenceWriterto write an array of root-level values, using configuration of thisObjectWriter.SequenceWriterwriteValuesAsArray(OutputStream out)Method for creating aSequenceWriterto write an array of root-level values, using configuration of thisObjectWriter.SequenceWriterwriteValuesAsArray(Writer out)Method for creating aSequenceWriterto write an array of root-level values, using configuration of thisObjectWriter.
-
-
-
Field Detail
-
NULL_PRETTY_PRINTER
protected static final 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.
-
_config
protected final SerializationConfig _config
General serialization configuration settings
-
_serializerProvider
protected final DefaultSerializerProvider _serializerProvider
-
_serializerFactory
protected final SerializerFactory _serializerFactory
-
_generatorFactory
protected final com.fasterxml.jackson.core.JsonFactory _generatorFactory
Factory used for constructingJsonGenerators
-
_generatorSettings
protected final ObjectWriter.GeneratorSettings _generatorSettings
Container for settings that need to be passed toJsonGeneratorconstructed for serializing values.- Since:
- 2.5
-
_prefetch
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. This allows avoiding further serializer lookups and increases performance a bit on cases where readers are reused.- Since:
- 2.5
-
-
Constructor Detail
-
ObjectWriter
protected ObjectWriter(ObjectMapper mapper, SerializationConfig config, JavaType rootType, com.fasterxml.jackson.core.PrettyPrinter pp)
Constructor used byObjectMapperfor initial instantiation
-
ObjectWriter
protected ObjectWriter(ObjectMapper mapper, SerializationConfig config)
Alternative constructor for initial instantiation byObjectMapper
-
ObjectWriter
protected ObjectWriter(ObjectMapper mapper, SerializationConfig config, com.fasterxml.jackson.core.FormatSchema s)
Alternative constructor for initial instantiation byObjectMapper
-
ObjectWriter
protected ObjectWriter(ObjectWriter base, SerializationConfig config, ObjectWriter.GeneratorSettings genSettings, ObjectWriter.Prefetch prefetch)
Copy constructor used for building variations.
-
ObjectWriter
protected ObjectWriter(ObjectWriter base, SerializationConfig config)
Copy constructor used for building variations.
-
ObjectWriter
protected ObjectWriter(ObjectWriter base, com.fasterxml.jackson.core.JsonFactory f)
- Since:
- 2.3
-
-
Method Detail
-
version
public com.fasterxml.jackson.core.Version version()
Method that will return version information stored in and read from jar that contains this class.- Specified by:
versionin interfacecom.fasterxml.jackson.core.Versioned
-
_new
protected ObjectWriter _new(ObjectWriter base, com.fasterxml.jackson.core.JsonFactory f)
Overridable factory method called by various "withXxx()" methods- Since:
- 2.5
-
_new
protected ObjectWriter _new(ObjectWriter base, SerializationConfig config)
Overridable factory method called by various "withXxx()" methods- Since:
- 2.5
-
_new
protected ObjectWriter _new(ObjectWriter.GeneratorSettings genSettings, ObjectWriter.Prefetch prefetch)
Overridable factory method called by various "withXxx()" methods. It assumes `this` as base for settings other than those directly passed in.- Since:
- 2.5
-
_newSequenceWriter
protected SequenceWriter _newSequenceWriter(boolean wrapInArray, com.fasterxml.jackson.core.JsonGenerator gen, boolean managedInput) throws IOException
Overridable factory method called bywriteValues(OutputStream)method (and its various overrides), and initializes it as necessary.- Throws:
IOException- Since:
- 2.5
-
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 enabled.
-
without
public ObjectWriter without(SerializationFeature first, SerializationFeature... other)
Method for constructing a new instance that is configured with specified features enabled.
-
withoutFeatures
public ObjectWriter withoutFeatures(SerializationFeature... features)
Method for constructing a new instance that is configured with specified features enabled.
-
with
public ObjectWriter with(com.fasterxml.jackson.core.JsonGenerator.Feature feature)
- Since:
- 2.5
-
withFeatures
public ObjectWriter withFeatures(com.fasterxml.jackson.core.JsonGenerator.Feature... features)
- Since:
- 2.5
-
without
public ObjectWriter without(com.fasterxml.jackson.core.JsonGenerator.Feature feature)
- Since:
- 2.5
-
withoutFeatures
public ObjectWriter withoutFeatures(com.fasterxml.jackson.core.JsonGenerator.Feature... features)
- Since:
- 2.5
-
with
public ObjectWriter with(com.fasterxml.jackson.core.FormatFeature feature)
- Since:
- 2.7
-
withFeatures
public ObjectWriter withFeatures(com.fasterxml.jackson.core.FormatFeature... features)
- Since:
- 2.7
-
without
public ObjectWriter without(com.fasterxml.jackson.core.FormatFeature feature)
- Since:
- 2.7
-
withoutFeatures
public ObjectWriter withoutFeatures(com.fasterxml.jackson.core.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(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(com.fasterxml.jackson.core.type.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(Class<?> rootType)
Deprecated.since 2.5 UseforType(Class)instead
-
withType
@Deprecated public ObjectWriter withType(com.fasterxml.jackson.core.type.TypeReference<?> rootType)
Deprecated.since 2.5 UseforType(TypeReference)instead
-
with
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.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(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)
-
withRootName
public ObjectWriter withRootName(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(com.fasterxml.jackson.core.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(com.fasterxml.jackson.core.FormatSchema schema)
Deprecated.Since 2.5 usewith(FormatSchema)instead
-
withView
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.
-
with
public ObjectWriter with(Locale l)
-
with
public ObjectWriter with(TimeZone tz)
-
with
public ObjectWriter with(com.fasterxml.jackson.core.Base64Variant b64variant)
Method that will construct a new instance that uses specified defaultBase64Variantfor base64 encoding- Since:
- 2.1
-
with
public ObjectWriter with(com.fasterxml.jackson.core.io.CharacterEscapes escapes)
- Since:
- 2.3
-
with
public ObjectWriter with(com.fasterxml.jackson.core.JsonFactory f)
- Since:
- 2.3
-
with
public ObjectWriter with(ContextAttributes attrs)
- Since:
- 2.3
-
withAttributes
public ObjectWriter withAttributes(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(Object key, Object value)
- Since:
- 2.3
-
withoutAttribute
public ObjectWriter withoutAttribute(Object key)
- Since:
- 2.3
-
withRootValueSeparator
public ObjectWriter withRootValueSeparator(String sep)
- Since:
- 2.5
-
withRootValueSeparator
public ObjectWriter withRootValueSeparator(com.fasterxml.jackson.core.SerializableString sep)
- Since:
- 2.5
-
writeValues
public SequenceWriter writeValues(File out) throws 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:
IOException- Since:
- 2.5
-
writeValues
public SequenceWriter writeValues(com.fasterxml.jackson.core.JsonGenerator g) throws 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:
IOException- Since:
- 2.5
-
writeValues
public SequenceWriter writeValues(Writer out) throws 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:
IOException- Since:
- 2.5
-
writeValues
public SequenceWriter writeValues(OutputStream out) throws 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:
IOException- Since:
- 2.5
-
writeValues
public SequenceWriter writeValues(DataOutput out) throws IOException
- Throws:
IOException- Since:
- 2.8
-
writeValuesAsArray
public SequenceWriter writeValuesAsArray(File out) throws 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:
IOException- Since:
- 2.5
-
writeValuesAsArray
public SequenceWriter writeValuesAsArray(com.fasterxml.jackson.core.JsonGenerator gen) throws 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:
IOException- Since:
- 2.5
-
writeValuesAsArray
public SequenceWriter writeValuesAsArray(Writer out) throws 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:
IOException- Since:
- 2.5
-
writeValuesAsArray
public SequenceWriter writeValuesAsArray(OutputStream out) throws 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:
IOException- Since:
- 2.5
-
writeValuesAsArray
public SequenceWriter writeValuesAsArray(DataOutput out) throws IOException
- Throws:
IOException- Since:
- 2.8
-
isEnabled
public boolean isEnabled(SerializationFeature f)
-
isEnabled
public boolean isEnabled(MapperFeature f)
-
isEnabled
@Deprecated public boolean isEnabled(com.fasterxml.jackson.core.JsonParser.Feature f)
Deprecated.- Since:
- 2.9
-
isEnabled
public boolean isEnabled(com.fasterxml.jackson.core.JsonGenerator.Feature f)
- Since:
- 2.9
-
getConfig
public SerializationConfig getConfig()
- Since:
- 2.2
-
getFactory
public com.fasterxml.jackson.core.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(com.fasterxml.jackson.core.JsonGenerator g, Object value) throws IOExceptionMethod that can be used to serialize any Java value as JSON output, using providedJsonGenerator.- Throws:
IOException
-
writeValue
public void writeValue(File resultFile, Object value) throws IOException, com.fasterxml.jackson.core.JsonGenerationException, JsonMappingException
Method that can be used to serialize any Java value as JSON output, written to File provided.- Throws:
IOExceptioncom.fasterxml.jackson.core.JsonGenerationExceptionJsonMappingException
-
writeValue
public void writeValue(OutputStream out, Object value) throws IOException, com.fasterxml.jackson.core.JsonGenerationException, JsonMappingException
Method 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:
IOExceptioncom.fasterxml.jackson.core.JsonGenerationExceptionJsonMappingException
-
writeValue
public void writeValue(Writer w, Object value) throws IOException, com.fasterxml.jackson.core.JsonGenerationException, JsonMappingException
Method 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:
IOExceptioncom.fasterxml.jackson.core.JsonGenerationExceptionJsonMappingException
-
writeValue
public void writeValue(DataOutput out, Object value) throws IOException
- Throws:
IOException- Since:
- 2.8
-
writeValueAsString
public String writeValueAsString(Object value) throws com.fasterxml.jackson.core.JsonProcessingException
Method 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:
com.fasterxml.jackson.core.JsonProcessingException
-
writeValueAsBytes
public byte[] writeValueAsBytes(Object value) throws com.fasterxml.jackson.core.JsonProcessingException
Method 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:
com.fasterxml.jackson.core.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(Class<?> type, JsonFormatVisitorWrapper visitor) throws JsonMappingException
Since 2.6- Throws:
JsonMappingException
-
canSerialize
public boolean canSerialize(Class<?> type)
-
canSerialize
public boolean canSerialize(Class<?> type, AtomicReference<Throwable> cause)
Method for checking whether instances of given type can be serialized, and optionally why (as perThrowablereturned).- Since:
- 2.3
-
_serializerProvider
protected DefaultSerializerProvider _serializerProvider()
Overridable helper method used for constructingSerializerProviderto use for serialization.
-
_verifySchemaType
protected void _verifySchemaType(com.fasterxml.jackson.core.FormatSchema schema)
- Since:
- 2.2
-
_configAndWriteValue
protected final void _configAndWriteValue(com.fasterxml.jackson.core.JsonGenerator gen, Object value) throws IOExceptionMethod called to configure the generator as necessary and then call write functionality- Throws:
IOException
-
_configureGenerator
protected final void _configureGenerator(com.fasterxml.jackson.core.JsonGenerator gen)
Helper method called to set or override settings of passed-inJsonGenerator- Since:
- 2.5
-
-