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
ADocumentWriterandArrayWriterthat uses the Jackson library to write JSON.- Author:
- Randall Hauch
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classJacksonWriter.WritingError
-
Field Summary
Fields Modifier and Type Field Description private static com.fasterxml.jackson.core.JsonFactoryfactorystatic JacksonWriterINSTANCEprivate booleanprettystatic JacksonWriterPRETTY_WRITER
-
Constructor Summary
Constructors Modifier Constructor Description privateJacksonWriter(boolean pretty)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidconfigure(com.fasterxml.jackson.core.JsonGenerator generator)Stringwrite(Array array)Write the supplied array to a string using UTF-8.voidwrite(Array array, OutputStream jsonStream)Write the supplied array to bytes using UTF-8.voidwrite(Array array, Writer jsonWriter)Write the supplied array to bytes using UTF-8.Stringwrite(Document document)Write the supplied document to a string using UTF-8.voidwrite(Document document, OutputStream jsonStream)Write the supplied document to bytes using UTF-8.voidwrite(Document document, Writer jsonWriter)Write the supplied document to bytes using UTF-8.protected voidwriteArray(Array array, com.fasterxml.jackson.core.JsonGenerator generator)byte[]writeAsBytes(Document document)Write the supplied array to bytes using UTF-8.protected voidwriteDocument(Document document, com.fasterxml.jackson.core.JsonGenerator generator)protected voidwriteValue(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:DocumentWriterWrite the supplied document to bytes using UTF-8.- Specified by:
writein 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:DocumentWriterWrite the supplied document to bytes using UTF-8.- Specified by:
writein 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:DocumentWriterWrite the supplied document to a string using UTF-8.- Specified by:
writein 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:DocumentWriterWrite the supplied array to bytes using UTF-8.- Specified by:
writeAsBytesin 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:ArrayWriterWrite the supplied array to bytes using UTF-8.- Specified by:
writein 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:ArrayWriterWrite the supplied array to bytes using UTF-8.- Specified by:
writein 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:ArrayWriterWrite the supplied array to a string using UTF-8.- Specified by:
writein 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
-
-