org.apache.uima.json.impl

## Class JsonContentHandlerJacksonWrapper

- java.lang.Object
- - org.apache.uima.json.impl.JsonContentHandlerJacksonWrapper

- All Implemented Interfaces:
    ContentHandler

      public class JsonContentHandlerJacksonWrapper
      extends Object
      implements 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
    Modifier and Type | Field and Description
    --- | ---
    `static String` | `SYSTEM_LINE_FEED`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `JsonContentHandlerJacksonWrapper(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 instance
    `JsonContentHandlerJacksonWrapper(com.fasterxml.jackson.core.JsonGenerator jsonGenerator, boolean isFormattedOutput)` Makes a Json content handler, using a specified JsonGenerator instance
    `JsonContentHandlerJacksonWrapper(Object destination)` Makes a Json content handler that sends its output to the specified destination
    `JsonContentHandlerJacksonWrapper(Object o, boolean isFormattedOutput)` Makes a Json content handler, and specifies a prettyprinting boolean flag (default is no prettyprinting).

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `characters(char[] ch, int start, int length)`
    `void` | `endDocument()`
    `void` | `endElement(String uri, String localName, String qName)`
    `void` | `endPrefixMapping(String prefix)`
    `com.fasterxml.jackson.core.JsonGenerator` | `getJsonGenerator()`
    `void` | `ignorableWhitespace(char[] ch, int start, int length)`
    `boolean` | `isFormattedOutput()`
    `void` | `processingInstruction(String target, String data)`
    `void` | `setDocumentLocator(Locator locator)`
    `void` | `skippedEntity(String name)`
    `void` | `startDocument()`
    `void` | `startElement(String uri, String localName, String qName, Attributes atts)`
    `void` | `startPrefixMapping(String prefix, String uri)`
    `void` | `withNl()`
    `void` | `withoutNl()`
    `void` | `writeNlJustBeforeNext()` 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`

- - ### Field Detail

    - #### SYSTEM_LINE_FEED

          public static final String SYSTEM_LINE_FEED

  - ### Constructor Detail

    - #### JsonContentHandlerJacksonWrapper

          public JsonContentHandlerJacksonWrapper(Object destination)
                                           throws SAXException

      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

          public JsonContentHandlerJacksonWrapper(Object o,
                                                  boolean isFormattedOutput)
                                           throws SAXException

      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 goes
        `isFormattedOutput` - -
      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 goes
        `isFormattedOutput` - - 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 Detail

    - #### 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

          public void characters(char[] ch,
                                 int start,
                                 int length)
                          throws SAXException

      Specified by:
        `characters` in interface `ContentHandler`
      Throws:
        `SAXException`

    - #### endDocument

          public void endDocument()
                           throws SAXException

      Specified by:
        `endDocument` in interface `ContentHandler`
      Throws:
        `SAXException`

    - #### endPrefixMapping

          public void endPrefixMapping(String prefix)
                                throws SAXException

      Specified by:
        `endPrefixMapping` in interface `ContentHandler`
      Throws:
        `SAXException`

    - #### ignorableWhitespace

          public void ignorableWhitespace(char[] ch,
                                          int start,
                                          int length)
                                   throws SAXException

      Specified by:
        `ignorableWhitespace` in interface `ContentHandler`
      Throws:
        `SAXException`

    - #### processingInstruction

          public void processingInstruction(String target,
                                            String data)
                                     throws SAXException

      Specified by:
        `processingInstruction` in interface `ContentHandler`
      Throws:
        `SAXException`

    - #### setDocumentLocator

          public void setDocumentLocator(Locator locator)

      Specified by:
        `setDocumentLocator` in interface `ContentHandler`

    - #### skippedEntity

          public void skippedEntity(String name)
                             throws SAXException

      Specified by:
        `skippedEntity` in interface `ContentHandler`
      Throws:
        `SAXException`

    - #### startDocument

          public void startDocument()
                             throws SAXException

      Specified by:
        `startDocument` in interface `ContentHandler`
      Throws:
        `SAXException`

    - #### startPrefixMapping

          public void startPrefixMapping(String prefix,
                                         String uri)
                                  throws SAXException

      Specified by:
        `startPrefixMapping` in interface `ContentHandler`
      Throws:
        `SAXException`

    - #### startElement

          public void startElement(String uri,
                                   String localName,
                                   String qName,
                                   Attributes atts)
                            throws SAXException

      Specified by:
        `startElement` in interface `ContentHandler`
      Throws:
        `SAXException`

    - #### endElement

          public void endElement(String uri,
                                 String localName,
                                 String qName)
                          throws SAXException

      Specified by:
        `endElement` in interface `ContentHandler`
      Throws:
        `SAXException`

    - #### withoutNl

          public void withoutNl()

    - #### withNl

          public void withNl()

Copyright © 2006–2021 The Apache Software Foundation. All rights reserved.