Package com.fasterxml.jackson.databind
Class SequenceWriter
- java.lang.Object
-
- com.fasterxml.jackson.databind.SequenceWriter
-
- All Implemented Interfaces:
Versioned,java.io.Closeable,java.io.Flushable,java.lang.AutoCloseable
public class SequenceWriter extends java.lang.Object implements Versioned, java.io.Closeable, java.io.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
-
-
Constructor Summary
Constructors Constructor Description SequenceWriter(DefaultSerializerProvider prov, JsonGenerator gen, boolean closeGenerator, ObjectWriter.Prefetch prefetch)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()voidflush()SequenceWriterinit(boolean wrapInArray)Internal method called byObjectWriter: should not be called by code outsidejackson-databindclasses.Versionversion()Method that will return version information stored in and read from jar that contains this class.SequenceWriterwrite(java.lang.Object value)Method for writing given value into output, as part of sequence to write.SequenceWriterwrite(java.lang.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 java.util.Collection<?>>
SequenceWriterwriteAll(C container)SequenceWriterwriteAll(java.lang.Iterable<?> iterable)SequenceWriterwriteAll(java.lang.Object[] value)
-
-
-
Constructor Detail
-
SequenceWriter
public SequenceWriter(DefaultSerializerProvider prov, JsonGenerator gen, boolean closeGenerator, ObjectWriter.Prefetch prefetch) throws java.io.IOException
- Throws:
java.io.IOException
-
-
Method Detail
-
init
public SequenceWriter init(boolean wrapInArray) throws java.io.IOException
Internal method called byObjectWriter: should not be called by code outsidejackson-databindclasses.- Throws:
java.io.IOException
-
version
public Version version()
Method that will return version information stored in and read from jar that contains this class.
-
write
public SequenceWriter write(java.lang.Object value) throws java.io.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:
java.io.IOException
-
write
public SequenceWriter write(java.lang.Object value, JavaType type) throws java.io.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:
java.io.IOException
-
writeAll
public SequenceWriter writeAll(java.lang.Object[] value) throws java.io.IOException
- Throws:
java.io.IOException
-
writeAll
public <C extends java.util.Collection<?>> SequenceWriter writeAll(C container) throws java.io.IOException
- Throws:
java.io.IOException
-
writeAll
public SequenceWriter writeAll(java.lang.Iterable<?> iterable) throws java.io.IOException
- Throws:
java.io.IOException- Since:
- 2.7
-
flush
public void flush() throws java.io.IOException- Specified by:
flushin interfacejava.io.Flushable- Throws:
java.io.IOException
-
close
public void close() throws java.io.IOException- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Throws:
java.io.IOException
-
-