Package com.fasterxml.jackson.databind
Class SequenceWriter
- java.lang.Object
-
- com.fasterxml.jackson.databind.SequenceWriter
-
- All Implemented Interfaces:
com.fasterxml.jackson.core.Versioned,Closeable,Flushable,AutoCloseable
public class SequenceWriter extends Object implements com.fasterxml.jackson.core.Versioned, Closeable, Flushable
Writer class similar toObjectWriter, except that it can be used for writing sequences of values, not just a single value. The main use case is in writing very long sequences, or sequences where values are incrementally produced; cases where it would be impractical or at least inconvenient to construct a wrapper container around values (or where no JSON array is desired around values).Differences from
ObjectWriterinclude:- Instances of
SequenceWriterare stateful, and not thread-safe: if sharing, external synchronization must be used. - Explicit
close()is needed after all values have been written (ObjectWritercan auto-close after individual value writes)
- Since:
- 2.5
-
-
Field Summary
Fields Modifier and Type Field Description protected boolean_cfgCloseCloseableprotected boolean_cfgFlushprotected boolean_closedprotected boolean_closeGeneratorprotected SerializationConfig_configprotected PropertySerializerMap_dynamicSerializersIf_rootSerializeris not defined (no root type was used for constructingObjectWriter), we will use simple scheme for keeping track of serializers needed.protected com.fasterxml.jackson.core.JsonGenerator_generatorprotected boolean_openArrayState flag for keeping track of need to write matching END_ARRAY, if a START_ARRAY was written during initializationprotected DefaultSerializerProvider_providerprotected JsonSerializer<Object>_rootSerializerprotected TypeSerializer_typeSerializer
-
Constructor Summary
Constructors Constructor Description SequenceWriter(DefaultSerializerProvider prov, com.fasterxml.jackson.core.JsonGenerator gen, boolean closeGenerator, ObjectWriter.Prefetch prefetch)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected SequenceWriter_writeCloseableValue(Object value)protected SequenceWriter_writeCloseableValue(Object value, JavaType type)voidclose()voidflush()SequenceWriterinit(boolean wrapInArray)Internal method called byObjectWriter: should not be called by code outsidejackson-databindclasses.com.fasterxml.jackson.core.Versionversion()Method that will return version information stored in and read from jar that contains this class.SequenceWriterwrite(Object value)Method for writing given value into output, as part of sequence to write.SequenceWriterwrite(Object value, JavaType type)Method for writing given value into output, as part of sequence to write; further, full type (often generic, likeMapis passed in case a newJsonSerializerneeds to be fetched to handle type If root type was specified forObjectWriter, value must be of compatible type (same or subtype).<C extends Collection<?>>
SequenceWriterwriteAll(C container)SequenceWriterwriteAll(Iterable<?> iterable)SequenceWriterwriteAll(Object[] value)
-
-
-
Field Detail
-
_provider
protected final DefaultSerializerProvider _provider
-
_config
protected final SerializationConfig _config
-
_generator
protected final com.fasterxml.jackson.core.JsonGenerator _generator
-
_rootSerializer
protected final JsonSerializer<Object> _rootSerializer
-
_typeSerializer
protected final TypeSerializer _typeSerializer
-
_closeGenerator
protected final boolean _closeGenerator
-
_cfgFlush
protected final boolean _cfgFlush
-
_cfgCloseCloseable
protected final boolean _cfgCloseCloseable
-
_dynamicSerializers
protected PropertySerializerMap _dynamicSerializers
If_rootSerializeris not defined (no root type was used for constructingObjectWriter), we will use simple scheme for keeping track of serializers needed. Assumption is that
-
_openArray
protected boolean _openArray
State flag for keeping track of need to write matching END_ARRAY, if a START_ARRAY was written during initialization
-
_closed
protected boolean _closed
-
-
Constructor Detail
-
SequenceWriter
public SequenceWriter(DefaultSerializerProvider prov, com.fasterxml.jackson.core.JsonGenerator gen, boolean closeGenerator, ObjectWriter.Prefetch prefetch) throws IOException
- Throws:
IOException
-
-
Method Detail
-
init
public SequenceWriter init(boolean wrapInArray) throws IOException
Internal method called byObjectWriter: should not be called by code outsidejackson-databindclasses.- Throws:
IOException
-
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
-
write
public SequenceWriter write(Object value) throws IOException
Method for writing given value into output, as part of sequence to write. If root type was specified forObjectWriter, value must be of compatible type (same or subtype).- Throws:
IOException
-
write
public SequenceWriter write(Object value, JavaType type) throws IOException
Method for writing given value into output, as part of sequence to write; further, full type (often generic, likeMapis passed in case a newJsonSerializerneeds to be fetched to handle type If root type was specified forObjectWriter, value must be of compatible type (same or subtype).- Throws:
IOException
-
writeAll
public SequenceWriter writeAll(Object[] value) throws IOException
- Throws:
IOException
-
writeAll
public <C extends Collection<?>> SequenceWriter writeAll(C container) throws IOException
- Throws:
IOException
-
writeAll
public SequenceWriter writeAll(Iterable<?> iterable) throws IOException
- Throws:
IOException- Since:
- 2.7
-
flush
public void flush() throws IOException- Specified by:
flushin interfaceFlushable- Throws:
IOException
-
close
public void close() throws IOException- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
_writeCloseableValue
protected SequenceWriter _writeCloseableValue(Object value) throws IOException
- Throws:
IOException
-
_writeCloseableValue
protected SequenceWriter _writeCloseableValue(Object value, JavaType type) throws IOException
- Throws:
IOException
-
-