Package com.fasterxml.jackson.databind
Class SequenceWriter
java.lang.Object
com.fasterxml.jackson.databind.SequenceWriter
- All Implemented Interfaces:
Versioned,Closeable,Flushable,AutoCloseable
Writer class similar to
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:
- 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
FieldsModifier and TypeFieldDescriptionprotected final booleanprotected final booleanprotected booleanprotected final booleanprotected final SerializationConfigprotected PropertySerializerMapIf_rootSerializeris not defined (no root type was used for constructingObjectWriter), we will use simple scheme for keeping track of serializers needed.protected final JsonGeneratorprotected booleanState flag for keeping track of need to write matching END_ARRAY, if a START_ARRAY was written during initializationprotected final DefaultSerializerProviderprotected final JsonSerializer<Object>protected final TypeSerializer -
Constructor Summary
ConstructorsConstructorDescriptionSequenceWriter(DefaultSerializerProvider prov, JsonGenerator gen, boolean closeGenerator, ObjectWriter.Prefetch prefetch) -
Method Summary
Modifier and TypeMethodDescriptionprotected SequenceWriter_writeCloseableValue(Object value) protected SequenceWriter_writeCloseableValue(Object value, JavaType type) voidclose()voidflush()init(boolean wrapInArray) Internal method called byObjectWriter: should not be called by code outsidejackson-databindclasses.version()Method that will return version information stored in and read from jar that contains this class.Method for writing given value into output, as part of sequence to write.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)
-
Field Details
-
_provider
-
_config
-
_generator
-
_rootSerializer
-
_typeSerializer
-
_closeGenerator
protected final boolean _closeGenerator -
_cfgFlush
protected final boolean _cfgFlush -
_cfgCloseCloseable
protected final boolean _cfgCloseCloseable -
_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 _openArrayState flag for keeping track of need to write matching END_ARRAY, if a START_ARRAY was written during initialization -
_closed
protected boolean _closed
-
-
Constructor Details
-
SequenceWriter
public SequenceWriter(DefaultSerializerProvider prov, JsonGenerator gen, boolean closeGenerator, ObjectWriter.Prefetch prefetch) throws IOException - Throws:
IOException
-
-
Method Details
-
init
Internal method called byObjectWriter: should not be called by code outsidejackson-databindclasses.- Throws:
IOException
-
version
Method that will return version information stored in and read from jar that contains this class. -
write
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
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
- Throws:
IOException
-
writeAll
- Throws:
IOException
-
writeAll
- Throws:
IOException- Since:
- 2.7
-
flush
- Specified by:
flushin interfaceFlushable- Throws:
IOException
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
_writeCloseableValue
- Throws:
IOException
-
_writeCloseableValue
- Throws:
IOException
-