Package org.apache.uima.json.impl
Class JsonContentHandlerJacksonWrapper
java.lang.Object
org.apache.uima.json.impl.JsonContentHandlerJacksonWrapper
- All Implemented Interfaces:
ContentHandler
Utility class that generates JSON output for UIMA descriptors and CASs
This class is built as a wrapper for a popular open-source implementation of JSON capabilities, "Jackson".
Unusually, it implements the ContentHandler interface, so it can be use with the existing code in UIMA which uses
content handlers for serialization.
Because of this, it wraps the IOExceptions that the Jackson package throws, into SAXExceptions that ContentHandlers throw.
Use: Create an instance, specifying the output as a Writer or OutputStream or File
(These three forms are supported by the underlying Jackson impl)
Specify also if doing pretty-printing
Call from other serialization class that does walking (either MetaDataObject_impl or XmiCasSerializer),
to this instance
This class is exposes the Jackson "Generator" API for streaming, and
instances of the Jackson Factory instance for configuring.
The caller uses both this class and the Jackson Generator class.
This class lets the underlying Jackson PrettyPrinter classes track the indent level.
PrettyPrinting is implemented via customization of the Jackson PrettyPrinting classes
-
Field Summary
-
Constructor Summary
ConstructorDescriptionJsonContentHandlerJacksonWrapper
(com.fasterxml.jackson.core.JsonFactory jsonFactory, Object o) Makes a Json content handler, using a specified JsonFactory instance that can be configured according to the Jackson implementation.JsonContentHandlerJacksonWrapper
(com.fasterxml.jackson.core.JsonFactory jsonFactory, Object o, boolean isFormattedOutput) Makes a Json content handler, using a specified JsonFactory instance that can be configured according to the Jackson implementation, and specifies a prettyprinting boolean flag (default is no prettyprinting).JsonContentHandlerJacksonWrapper
(com.fasterxml.jackson.core.JsonGenerator jsonGenerator) Makes a Json content handler, using a specified JsonGenerator instanceJsonContentHandlerJacksonWrapper
(com.fasterxml.jackson.core.JsonGenerator jsonGenerator, boolean isFormattedOutput) Makes a Json content handler, using a specified JsonGenerator instanceJsonContentHandlerJacksonWrapper
(Object destination) Makes a Json content handler that sends its output to the specified destinationJsonContentHandlerJacksonWrapper
(Object o, boolean isFormattedOutput) Makes a Json content handler, and specifies a prettyprinting boolean flag (default is no prettyprinting). -
Method Summary
Modifier and TypeMethodDescriptionvoid
characters
(char[] ch, int start, int length) void
void
endElement
(String uri, String localName, String qName) void
endPrefixMapping
(String prefix) com.fasterxml.jackson.core.JsonGenerator
void
ignorableWhitespace
(char[] ch, int start, int length) boolean
void
processingInstruction
(String target, String data) void
setDocumentLocator
(Locator locator) void
skippedEntity
(String name) void
void
startElement
(String uri, String localName, String qName, Attributes atts) void
startPrefixMapping
(String prefix, String uri) void
withNl()
void
void
Call this to indicate that the prettyprinter should write a new line just before the next significant output.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.xml.sax.ContentHandler
declaration
-
Field Details
-
SYSTEM_LINE_FEED
-
-
Constructor Details
-
JsonContentHandlerJacksonWrapper
Makes a Json content handler that sends its output to the specified destination- Parameters:
destination
- - can be a File, an OutputStream, or a Writer- Throws:
SAXException
- wrapping an IOException
-
JsonContentHandlerJacksonWrapper
public JsonContentHandlerJacksonWrapper(com.fasterxml.jackson.core.JsonFactory jsonFactory, Object o) throws SAXException Makes a Json content handler, using a specified JsonFactory instance that can be configured according to the Jackson implementation. The resulting content handler will send its output to the specified destination- Parameters:
jsonFactory
- -o
- - where the output goes- Throws:
SAXException
- wrapping an IOException
-
JsonContentHandlerJacksonWrapper
Makes a Json content handler, and specifies a prettyprinting boolean flag (default is no prettyprinting). The resulting content handler will send its output to the specified destination- Parameters:
o
- - where the output goesisFormattedOutput
- -- Throws:
SAXException
- wrapping an IOException
-
JsonContentHandlerJacksonWrapper
public JsonContentHandlerJacksonWrapper(com.fasterxml.jackson.core.JsonFactory jsonFactory, Object o, boolean isFormattedOutput) throws SAXException Makes a Json content handler, using a specified JsonFactory instance that can be configured according to the Jackson implementation, and specifies a prettyprinting boolean flag (default is no prettyprinting). The resulting content handler will send its output to the specified destination- Parameters:
jsonFactory
- -o
- where the output goesisFormattedOutput
- - true for pretty printing- Throws:
SAXException
- wrapping an IOException
-
JsonContentHandlerJacksonWrapper
public JsonContentHandlerJacksonWrapper(com.fasterxml.jackson.core.JsonGenerator jsonGenerator) Makes a Json content handler, using a specified JsonGenerator instance- Parameters:
jsonGenerator
- -
-
JsonContentHandlerJacksonWrapper
public JsonContentHandlerJacksonWrapper(com.fasterxml.jackson.core.JsonGenerator jsonGenerator, boolean isFormattedOutput) Makes a Json content handler, using a specified JsonGenerator instance- Parameters:
jsonGenerator
- -isFormattedOutput
- - set to true for prettyprinting, default is false
-
-
Method Details
-
isFormattedOutput
public boolean isFormattedOutput() -
getJsonGenerator
public com.fasterxml.jackson.core.JsonGenerator getJsonGenerator() -
writeNlJustBeforeNext
public void writeNlJustBeforeNext()Call this to indicate that the prettyprinter should write a new line just before the next significant output. It won't do this before a "comma", and some other punctuation. Has no effect if no prettyprinting is being done. -
characters
- Specified by:
characters
in interfaceContentHandler
- Throws:
SAXException
-
endDocument
- Specified by:
endDocument
in interfaceContentHandler
- Throws:
SAXException
-
endPrefixMapping
- Specified by:
endPrefixMapping
in interfaceContentHandler
- Throws:
SAXException
-
ignorableWhitespace
- Specified by:
ignorableWhitespace
in interfaceContentHandler
- Throws:
SAXException
-
processingInstruction
- Specified by:
processingInstruction
in interfaceContentHandler
- Throws:
SAXException
-
setDocumentLocator
- Specified by:
setDocumentLocator
in interfaceContentHandler
-
skippedEntity
- Specified by:
skippedEntity
in interfaceContentHandler
- Throws:
SAXException
-
startDocument
- Specified by:
startDocument
in interfaceContentHandler
- Throws:
SAXException
-
startPrefixMapping
- Specified by:
startPrefixMapping
in interfaceContentHandler
- Throws:
SAXException
-
startElement
public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException - Specified by:
startElement
in interfaceContentHandler
- Throws:
SAXException
-
endElement
- Specified by:
endElement
in interfaceContentHandler
- Throws:
SAXException
-
withoutNl
public void withoutNl() -
withNl
public void withNl()
-