Class 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 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)
      • 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
      • 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
      • 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