Package io.debezium.document
Class JacksonWriter
- java.lang.Object
-
- io.debezium.document.JacksonWriter
-
- All Implemented Interfaces:
ArrayWriter
,DocumentWriter
@ThreadSafe final class JacksonWriter extends Object implements DocumentWriter, ArrayWriter
ADocumentWriter
andArrayWriter
that uses the Jackson library to write JSON.- Author:
- Randall Hauch
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
JacksonWriter.WritingError
-
Field Summary
Fields Modifier and Type Field Description private static com.fasterxml.jackson.core.JsonFactory
factory
static JacksonWriter
INSTANCE
private boolean
pretty
static JacksonWriter
PRETTY_WRITER
-
Constructor Summary
Constructors Modifier Constructor Description private
JacksonWriter(boolean pretty)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
configure(com.fasterxml.jackson.core.JsonGenerator generator)
String
write(Array array)
Write the supplied array to a string using UTF-8.void
write(Array array, OutputStream jsonStream)
Write the supplied array to bytes using UTF-8.void
write(Array array, Writer jsonWriter)
Write the supplied array to bytes using UTF-8.String
write(Document document)
Write the supplied document to a string using UTF-8.void
write(Document document, OutputStream jsonStream)
Write the supplied document to bytes using UTF-8.void
write(Document document, Writer jsonWriter)
Write the supplied document to bytes using UTF-8.protected void
writeArray(Array array, com.fasterxml.jackson.core.JsonGenerator generator)
byte[]
writeAsBytes(Document document)
Write the supplied array to bytes using UTF-8.protected void
writeDocument(Document document, com.fasterxml.jackson.core.JsonGenerator generator)
protected void
writeValue(Value value, com.fasterxml.jackson.core.JsonGenerator generator)
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface io.debezium.document.ArrayWriter
writeAsBytes
-
-
-
-
Field Detail
-
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
-
-
Method Detail
-
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 interfaceDocumentWriter
- Parameters:
document
- the array to be written; may not be nulljsonStream
- 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 interfaceDocumentWriter
- Parameters:
document
- the array to be written; may not be nulljsonWriter
- 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 interfaceDocumentWriter
- 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 interfaceDocumentWriter
- 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 interfaceArrayWriter
- Parameters:
array
- the array to be written; may not be nulljsonStream
- 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 interfaceArrayWriter
- Parameters:
array
- the array to be written; may not be nulljsonWriter
- 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 interfaceArrayWriter
- 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
-
-