Class SequenceWriter

java.lang.Object
tools.jackson.databind.SequenceWriter
All Implemented Interfaces:
Closeable, Flushable, AutoCloseable, tools.jackson.core.Versioned

public class SequenceWriter extends Object implements tools.jackson.core.Versioned, Closeable, 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)
  • Field Details

    • _provider

      protected final SerializationContextExt _provider
    • _config

      protected final SerializationConfig _config
    • _generator

      protected final tools.jackson.core.JsonGenerator _generator
    • _rootSerializer

      protected final ValueSerializer<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 Details

  • Method Details

    • init

      public SequenceWriter init(boolean wrapInArray) throws tools.jackson.core.JacksonException
      Internal method called by ObjectWriter: should not be called by code outside jackson-databind classes.
      Throws:
      tools.jackson.core.JacksonException
    • version

      public tools.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 tools.jackson.core.Versioned
    • write

      public SequenceWriter write(Object value) throws tools.jackson.core.JacksonException
      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:
      tools.jackson.core.JacksonException
    • write

      public SequenceWriter write(Object value, JavaType type) throws tools.jackson.core.JacksonException
      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 ValueSerializer needs to be fetched to handle type If root type was specified for ObjectWriter, value must be of compatible type (same or subtype).
      Throws:
      tools.jackson.core.JacksonException
    • writeAll

      public SequenceWriter writeAll(Object[] value) throws tools.jackson.core.JacksonException
      Throws:
      tools.jackson.core.JacksonException
    • writeAll

      public <C extends Collection<?>> SequenceWriter writeAll(C container) throws tools.jackson.core.JacksonException
      Throws:
      tools.jackson.core.JacksonException
    • writeAll

      public SequenceWriter writeAll(Iterable<?> iterable) throws tools.jackson.core.JacksonException
      Throws:
      tools.jackson.core.JacksonException
    • flush

      public void flush()
      Specified by:
      flush in interface Flushable
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
    • _writeCloseableValue

      protected SequenceWriter _writeCloseableValue(Object value) throws tools.jackson.core.JacksonException
      Throws:
      tools.jackson.core.JacksonException
    • _writeCloseableValue

      protected SequenceWriter _writeCloseableValue(Object value, JavaType type) throws tools.jackson.core.JacksonException
      Throws:
      tools.jackson.core.JacksonException