Class JsonSaxWriter

  • All Implemented Interfaces:
    SaxWriter

    class JsonSaxWriter
    extends java.lang.Object
    implements SaxWriter
    Implementation of SaxWriter which, perversely, generates a JSON (JavaScript Object Notation) document.
    Author:
    jhyde
    • Constructor Summary

      Constructors 
      Constructor Description
      JsonSaxWriter​(java.io.OutputStream outputStream)
      Creates a JsonSaxWriter.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void characters​(java.lang.String data)  
      void completeBeforeElement​(java.lang.String tagName)  
      void element​(java.lang.String name, java.lang.Object... attrs)  
      void endDocument()  
      void endElement()  
      void endSequence()
      Informs the writer that a sequence of elements of the same name has ended.
      void flush()
      Flushes any unwritten output.
      void startDocument()  
      void startElement​(java.lang.String name)  
      void startElement​(java.lang.String name, java.lang.Object... attrs)  
      void startSequence​(java.lang.String name, java.lang.String subName)
      Informs the writer that a sequence of elements of the same name is starting.
      void textElement​(java.lang.String name, java.lang.Object data)
      Generates a text-only element, <name>data</name>.
      void verbatim​(java.lang.String text)
      Sends a piece of text verbatim through the writer.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • JsonSaxWriter

        public JsonSaxWriter​(java.io.OutputStream outputStream)
        Creates a JsonSaxWriter.
        Parameters:
        outputStream - Output stream
    • Method Detail

      • startSequence

        public void startSequence​(java.lang.String name,
                                  java.lang.String subName)
        Description copied from interface: SaxWriter
        Informs the writer that a sequence of elements of the same name is starting.

        For XML, is equivalent to startElement(name).

        For JSON, initiates the array construct:

        "name" : [
          { ... },
          { ... }
        ]
        Specified by:
        startSequence in interface SaxWriter
        Parameters:
        name - Element name
        subName - Child element name
      • endSequence

        public void endSequence()
        Description copied from interface: SaxWriter
        Informs the writer that a sequence of elements of the same name has ended.
        Specified by:
        endSequence in interface SaxWriter
      • startElement

        public void startElement​(java.lang.String name)
        Specified by:
        startElement in interface SaxWriter
      • startElement

        public void startElement​(java.lang.String name,
                                 java.lang.Object... attrs)
        Specified by:
        startElement in interface SaxWriter
      • element

        public void element​(java.lang.String name,
                            java.lang.Object... attrs)
        Specified by:
        element in interface SaxWriter
      • characters

        public void characters​(java.lang.String data)
        Specified by:
        characters in interface SaxWriter
      • textElement

        public void textElement​(java.lang.String name,
                                java.lang.Object data)
        Description copied from interface: SaxWriter
        Generates a text-only element, <name>data</name>.

        For XML, this is equivalent to

        startElement(name);
        characters(data);
        endElement();
        but for JSON, generates "name": "data".
        Specified by:
        textElement in interface SaxWriter
        Parameters:
        name - Name of element
        data - Text content of element
      • completeBeforeElement

        public void completeBeforeElement​(java.lang.String tagName)
        Specified by:
        completeBeforeElement in interface SaxWriter
      • verbatim

        public void verbatim​(java.lang.String text)
        Description copied from interface: SaxWriter
        Sends a piece of text verbatim through the writer. It must be a piece of well-formed XML.
        Specified by:
        verbatim in interface SaxWriter
      • flush

        public void flush()
        Description copied from interface: SaxWriter
        Flushes any unwritten output.
        Specified by:
        flush in interface SaxWriter