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
Fields -
Constructor Summary
ConstructorsConstructorDescriptionJsonContentHandlerJacksonWrapper(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 TypeMethodDescriptionvoidcharacters(char[] ch, int start, int length) voidvoidendElement(String uri, String localName, String qName) voidendPrefixMapping(String prefix) com.fasterxml.jackson.core.JsonGeneratorvoidignorableWhitespace(char[] ch, int start, int length) booleanvoidprocessingInstruction(String target, String data) voidsetDocumentLocator(Locator locator) voidskippedEntity(String name) voidvoidstartElement(String uri, String localName, String qName, Attributes atts) voidstartPrefixMapping(String prefix, String uri) voidwithNl()voidvoidCall 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, waitMethods 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:
charactersin interfaceContentHandler- Throws:
SAXException
-
endDocument
- Specified by:
endDocumentin interfaceContentHandler- Throws:
SAXException
-
endPrefixMapping
- Specified by:
endPrefixMappingin interfaceContentHandler- Throws:
SAXException
-
ignorableWhitespace
- Specified by:
ignorableWhitespacein interfaceContentHandler- Throws:
SAXException
-
processingInstruction
- Specified by:
processingInstructionin interfaceContentHandler- Throws:
SAXException
-
setDocumentLocator
- Specified by:
setDocumentLocatorin interfaceContentHandler
-
skippedEntity
- Specified by:
skippedEntityin interfaceContentHandler- Throws:
SAXException
-
startDocument
- Specified by:
startDocumentin interfaceContentHandler- Throws:
SAXException
-
startPrefixMapping
- Specified by:
startPrefixMappingin interfaceContentHandler- Throws:
SAXException
-
startElement
public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException - Specified by:
startElementin interfaceContentHandler- Throws:
SAXException
-
endElement
- Specified by:
endElementin interfaceContentHandler- Throws:
SAXException
-
withoutNl
public void withoutNl() -
withNl
public void withNl()
-