public class SequenceWriter extends Object implements Versioned, Closeable, Flushable
ObjectWriter
, 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 ObjectWriter
include:
SequenceWriter
are stateful, and not thread-safe:
if sharing, external synchronization must be used.
close()
is needed after all values have been written
(ObjectWriter
can auto-close after individual value writes)
Modifier and Type | Field and Description |
---|---|
protected boolean |
_cfgCloseCloseable |
protected boolean |
_cfgFlush |
protected boolean |
_closed |
protected boolean |
_closeGenerator |
protected SerializationConfig |
_config |
protected PropertySerializerMap |
_dynamicSerializers
If
_rootSerializer is not defined (no root type
was used for constructing ObjectWriter ), we will
use simple scheme for keeping track of serializers needed. |
protected JsonGenerator |
_generator |
protected boolean |
_openArray
State flag for keeping track of need to write matching END_ARRAY,
if a START_ARRAY was written during initialization
|
protected DefaultSerializerProvider |
_provider |
protected JsonSerializer<Object> |
_rootSerializer |
protected TypeSerializer |
_typeSerializer |
Constructor and Description |
---|
SequenceWriter(DefaultSerializerProvider prov,
JsonGenerator gen,
boolean closeGenerator,
ObjectWriter.Prefetch prefetch) |
Modifier and Type | Method and Description |
---|---|
protected SequenceWriter |
_writeCloseableValue(Object value) |
protected SequenceWriter |
_writeCloseableValue(Object value,
JavaType type) |
void |
close() |
void |
flush() |
SequenceWriter |
init(boolean wrapInArray) |
Version |
version()
Method that will return version information stored in and read from jar
that contains this class.
|
SequenceWriter |
write(Object value)
Method for writing given value into output, as part of sequence
to write.
|
SequenceWriter |
write(Object value,
JavaType type)
Method for writing given value into output, as part of sequence
to write; further, full type (often generic, like
Map
is passed in case a new
JsonSerializer needs to be fetched to handle type
If root type was specified for ObjectWriter ,
value must be of compatible type (same or subtype). |
<C extends Collection<?>> |
writeAll(C container) |
SequenceWriter |
writeAll(Iterable<?> iterable) |
SequenceWriter |
writeAll(Object[] value) |
protected final DefaultSerializerProvider _provider
protected final SerializationConfig _config
protected final JsonGenerator _generator
protected final JsonSerializer<Object> _rootSerializer
protected final TypeSerializer _typeSerializer
protected final boolean _closeGenerator
protected final boolean _cfgFlush
protected final boolean _cfgCloseCloseable
protected PropertySerializerMap _dynamicSerializers
_rootSerializer
is not defined (no root type
was used for constructing ObjectWriter
), we will
use simple scheme for keeping track of serializers needed.
Assumption is thatprotected boolean _openArray
protected boolean _closed
public SequenceWriter(DefaultSerializerProvider prov, JsonGenerator gen, boolean closeGenerator, ObjectWriter.Prefetch prefetch) throws IOException
IOException
public SequenceWriter init(boolean wrapInArray) throws IOException
IOException
public Version version()
public SequenceWriter write(Object value) throws IOException
ObjectWriter
,
value must be of compatible type (same or subtype).IOException
public SequenceWriter write(Object value, JavaType type) throws IOException
Map
is passed in case a new
JsonSerializer
needs to be fetched to handle type
If root type was specified for ObjectWriter
,
value must be of compatible type (same or subtype).IOException
public SequenceWriter writeAll(Object[] value) throws IOException
IOException
public <C extends Collection<?>> SequenceWriter writeAll(C container) throws IOException
IOException
public SequenceWriter writeAll(Iterable<?> iterable) throws IOException
IOException
public void flush() throws IOException
flush
in interface Flushable
IOException
public void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
IOException
protected SequenceWriter _writeCloseableValue(Object value) throws IOException
IOException
protected SequenceWriter _writeCloseableValue(Object value, JavaType type) throws IOException
IOException
Copyright © 2008–2018 FasterXML. All rights reserved.