Package net.sf.saxon.ma.json

## Class JsonHandler

- java.lang.Object
- - net.sf.saxon.ma.json.JsonHandler

- Direct Known Subclasses:
    `JsonHandlerMap`, `JsonHandlerXML`

      public class JsonHandler
      extends java.lang.Object

  Default handler class for accepting the result from parsing JSON strings

- - ### Field Summary

    Fields
    Modifier and Type | Field | Description
    --- | --- | ---
    `protected java.util.function.IntPredicate` | `charChecker` |
    `boolean` | `escape` |

  - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `JsonHandler()` |

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `void` | `endArray()` | Close the current array
    `void` | `endMap()` | Close the current object/map
    `XPathContext` | `getContext()` |
    `Sequence` | `getResult()` |
    `protected void` | `handleInvalidCharacters​(FastStringBuffer buffer)` | Deal with invalid characters in the JSON string
    `protected void` | `markAsEscaped​(java.lang.CharSequence escaped, boolean isKey)` |
    `java.lang.String` | `reEscape​(java.lang.String val)` | Optionally apply escaping or unescaping to a value.
    `void` | `setContext​(XPathContext context)` |
    `void` | `setFallbackFunction​(java.util.Map<java.lang.String,​Sequence> options, XPathContext context)` |
    `boolean` | `setKey​(java.lang.String unEscaped, java.lang.String reEscaped)` | Set the key to be written for the next entry in an object/map
    `void` | `startArray()` | Open a new array
    `void` | `startMap()` | Start a new object/map
    `void` | `writeBoolean​(boolean value)` | Write a boolean value
    `void` | `writeNull()` | Write a null value
    `void` | `writeNumeric​(java.lang.String asString, double asDouble)` | Write a numeric value
    `void` | `writeString​(java.lang.String val)` | Write a string value

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### escape

          public boolean escape

    - #### charChecker

          protected java.util.function.IntPredicate charChecker

  - ### Constructor Detail

    - #### JsonHandler

          public JsonHandler()

  - ### Method Detail

    - #### setContext

          public void setContext​(XPathContext context)

    - #### getContext

          public XPathContext getContext()

    - #### getResult

          public Sequence getResult()
                             throws XPathException

      Throws:
        `XPathException`

    - #### setKey

          public boolean setKey​(java.lang.String unEscaped,
                                java.lang.String reEscaped)

      Set the key to be written for the next entry in an object/map
      Parameters:
        `unEscaped` - the key for the entry (null implies no key) in unescaped form (backslashes, if present, do not signal an escape sequence)
        `reEscaped` - the key for the entry (null implies no key) in reescaped form. In this form special characters are represented as backslash-escaped sequences if the escape option is yes; if escape=no, the reEscaped form is the same as the unEscaped form.
      Returns:
        true if the key is already present in the map, false if it is not

    - #### startArray

          public void startArray()
                          throws XPathException

      Open a new array
      Throws:
        `XPathException` - if any error occurs

    - #### endArray

          public void endArray()
                        throws XPathException

      Close the current array
      Throws:
        `XPathException` - if any error occurs

    - #### startMap

          public void startMap()
                        throws XPathException

      Start a new object/map
      Throws:
        `XPathException` - if any error occurs

    - #### endMap

          public void endMap()
                      throws XPathException

      Close the current object/map
      Throws:
        `XPathException` - if any error occurs

    - #### writeNumeric

          public void writeNumeric​(java.lang.String asString,
                                   double asDouble)
                            throws XPathException

      Write a numeric value
      Parameters:
        `asString` - the string representation of the value
        `asDouble` - the double representation of the value
      Throws:
        `XPathException` - if any error occurs

    - #### writeString

          public void writeString​(java.lang.String val)
                           throws XPathException

      Write a string value
      Parameters:
        `val` - The string to be written (which may or may not contain JSON escape sequences, according to the options that were set)
      Throws:
        `XPathException` - if any error occurs

    - #### reEscape

          public java.lang.String reEscape​(java.lang.String val)
                                    throws XPathException

      Optionally apply escaping or unescaping to a value.
      Parameters:
        `val` - the string to be escaped or unEscaped
      Returns:
        the escaped or unescaped string
      Throws:
        `XPathException`

    - #### writeBoolean

          public void writeBoolean​(boolean value)
                            throws XPathException

      Write a boolean value
      Parameters:
        `value` - the boolean value to be written
      Throws:
        `XPathException` - if any error occurs

    - #### writeNull

          public void writeNull()
                         throws XPathException

      Write a null value
      Throws:
        `XPathException` - if any error occurs

    - #### handleInvalidCharacters

          protected void handleInvalidCharacters​(FastStringBuffer buffer)
                                          throws XPathException

      Deal with invalid characters in the JSON string
      Parameters:
        `buffer` - the JSON string
      Throws:
        `XPathException` - if any error occurs

    - #### markAsEscaped

          protected void markAsEscaped​(java.lang.CharSequence escaped,
                                       boolean isKey)
                                throws XPathException

      Throws:
        `XPathException`

    - #### setFallbackFunction

          public void setFallbackFunction​(java.util.Map<java.lang.String,​Sequence> options,
                                          XPathContext context)
                                   throws XPathException

      Throws:
        `XPathException`