Class JacksonWriter

java.lang.Object
io.debezium.document.JacksonWriter
All Implemented Interfaces:
ArrayWriter, DocumentWriter

@ThreadSafe final class JacksonWriter extends Object implements DocumentWriter, ArrayWriter
A DocumentWriter and ArrayWriter that uses the Jackson library to write JSON.
Author:
Randall Hauch
  • Field Details

    • INSTANCE

      public static final JacksonWriter INSTANCE
    • PRETTY_WRITER

      public static final JacksonWriter PRETTY_WRITER
    • factory

      private static final com.fasterxml.jackson.core.JsonFactory factory
    • pretty

      private final boolean pretty
  • Constructor Details

    • JacksonWriter

      private JacksonWriter(boolean pretty)
  • Method Details

    • write

      public void write(Document document, OutputStream jsonStream) throws IOException
      Description copied from interface: DocumentWriter
      Write the supplied document to bytes using UTF-8.
      Specified by:
      write in interface DocumentWriter
      Parameters:
      document - the array to be written; may not be null
      jsonStream - the stream to which the document is to be written; may not be null
      Throws:
      IOException - if a document could not be written to the supplied stream
    • write

      public void write(Document document, Writer jsonWriter) throws IOException
      Description copied from interface: DocumentWriter
      Write the supplied document to bytes using UTF-8.
      Specified by:
      write in interface DocumentWriter
      Parameters:
      document - the array to be written; may not be null
      jsonWriter - the writer to which the document is to be written; may not be null
      Throws:
      IOException - if a document could not be written to the supplied stream
    • write

      public String write(Document document) throws IOException
      Description copied from interface: DocumentWriter
      Write the supplied document to a string using UTF-8.
      Specified by:
      write in interface DocumentWriter
      Parameters:
      document - the document to be written; may not be null
      Returns:
      the string containing the output JSON-formatted document; never null
      Throws:
      IOException - if a document could not be written to the supplied stream
    • writeAsBytes

      public byte[] writeAsBytes(Document document)
      Description copied from interface: DocumentWriter
      Write the supplied array to bytes using UTF-8.
      Specified by:
      writeAsBytes in interface DocumentWriter
      Parameters:
      document - the document to be written; may not be null
      Returns:
      the bytes containing the output JSON-formatted document; never null
    • write

      public void write(Array array, OutputStream jsonStream) throws IOException
      Description copied from interface: ArrayWriter
      Write the supplied array to bytes using UTF-8.
      Specified by:
      write in interface ArrayWriter
      Parameters:
      array - the array to be written; may not be null
      jsonStream - the stream to which the array is to be written; may not be null
      Throws:
      IOException - if an array could not be written to the supplied stream
    • write

      public void write(Array array, Writer jsonWriter) throws IOException
      Description copied from interface: ArrayWriter
      Write the supplied array to bytes using UTF-8.
      Specified by:
      write in interface ArrayWriter
      Parameters:
      array - the array to be written; may not be null
      jsonWriter - the IO writer to which the array is to be written; may not be null
      Throws:
      IOException - if an array could not be written to the supplied stream
    • write

      public String write(Array array) throws IOException
      Description copied from interface: ArrayWriter
      Write the supplied array to a string using UTF-8.
      Specified by:
      write in interface ArrayWriter
      Parameters:
      array - the array to be written; may not be null
      Returns:
      the string containing the output JSON-formatted array; never null
      Throws:
      IOException - if an array could not be written to the supplied stream
    • configure

      protected void configure(com.fasterxml.jackson.core.JsonGenerator generator)
    • writeDocument

      protected void writeDocument(Document document, com.fasterxml.jackson.core.JsonGenerator generator) throws IOException
      Throws:
      IOException
    • writeArray

      protected void writeArray(Array array, com.fasterxml.jackson.core.JsonGenerator generator) throws IOException
      Throws:
      IOException
    • writeValue

      protected void writeValue(Value value, com.fasterxml.jackson.core.JsonGenerator generator) throws IOException
      Throws:
      IOException