SequenceWriter
Date: 2016-12-04

com.fasterxml.jackson.databind

## Class SequenceWriter

- java.lang.Object
- - com.fasterxml.jackson.databind.SequenceWriter

- All Implemented Interfaces:
    com.fasterxml.jackson.core.Versioned, java.io.Closeable, java.io.Flushable, java.lang.AutoCloseable

      public class SequenceWriter
      extends java.lang.Object
      implements com.fasterxml.jackson.core.Versioned, java.io.Closeable, java.io.Flushable

  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 `SequenceWriter` are stateful, and not thread-safe: if sharing, external synchronization must be used.
  - Explicit `close()` is needed after all values have been written (`ObjectWriter` can auto-close after individual value writes)
  Since:
    2.5

- - ### Field Summary

    Fields
    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 com.fasterxml.jackson.core.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<java.lang.Object>` | `_rootSerializer`
    `protected TypeSerializer` | `_typeSerializer`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `SequenceWriter(DefaultSerializerProvider prov, com.fasterxml.jackson.core.JsonGenerator gen, boolean closeGenerator, ObjectWriter.Prefetch prefetch)`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected SequenceWriter` | `_writeCloseableValue(java.lang.Object value)`
    `protected SequenceWriter` | `_writeCloseableValue(java.lang.Object value, JavaType type)`
    `void` | `close()`
    `void` | `flush()`
    `SequenceWriter` | `init(boolean wrapInArray)`
    `com.fasterxml.jackson.core.Version` | `version()` Method that will return version information stored in and read from jar that contains this class.
    `SequenceWriter` | `write(java.lang.Object value)` Method for writing given value into output, as part of sequence to write.
    `SequenceWriter` | `write(java.lang.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 java.util.Collection<?>> SequenceWriter` | `writeAll(C container)`
    `SequenceWriter` | `writeAll(java.lang.Iterable<?> iterable)`
    `SequenceWriter` | `writeAll(java.lang.Object[] value)`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### 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<java.lang.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 `_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 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 java.io.IOException

      Throws:
        `java.io.IOException`

  - ### Method Detail

    - #### init

          public SequenceWriter init(boolean wrapInArray)
                              throws java.io.IOException

      Throws:
        `java.io.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:
        `version` in interface `com.fasterxml.jackson.core.Versioned`

    - #### 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 for `ObjectWriter`, 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, 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).
      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:
        `flush` in interface `java.io.Flushable`
      Throws:
        `java.io.IOException`

    - #### close

          public void close()
                     throws java.io.IOException

      Specified by:
        `close` in interface `java.io.Closeable`
      Specified by:
        `close` in interface `java.lang.AutoCloseable`
      Throws:
        `java.io.IOException`

    - #### _writeCloseableValue

          protected SequenceWriter _writeCloseableValue(java.lang.Object value)
                                                 throws java.io.IOException

      Throws:
        `java.io.IOException`

    - #### _writeCloseableValue

          protected SequenceWriter _writeCloseableValue(java.lang.Object value,
                                            JavaType type)
                                                 throws java.io.IOException

      Throws:
        `java.io.IOException`