Class JsonHandler

java.lang.Object
net.sf.saxon.ma.json.JsonHandler
Direct Known Subclasses:
JsonHandlerMap, JsonHandlerXML

public class JsonHandler extends Object
Default handler class for accepting the result from parsing JSON strings
  • Field Details

    • escape

      public boolean escape
    • charChecker

      protected IntPredicateProxy charChecker
  • Constructor Details

    • JsonHandler

      public JsonHandler()
  • Method Details

    • setContext

      public void setContext(XPathContext context)
    • getContext

      public XPathContext getContext()
    • getResult

      public Sequence getResult() throws XPathException
      Throws:
      XPathException
    • setKey

      public boolean setKey(String unEscaped, 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(String asString, AtomicValue parsedValue) throws XPathException
      Write a numeric value
      Parameters:
      asString - the raw string representation of the value
      parsedValue - the parsed representation of the value, typically an xs:double, but under user control
      Throws:
      XPathException - if any error occurs
    • writeString

      public void writeString(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 String reEscape(String val) throws XPathException
      Optionally apply escaping or unescaping to a value.
      Parameters:
      val - the string to be escaped or unEscaped. This is supplied as a String rather than a UnicodeString because there are special rules for handling unpaired surrogates, which cannot be represented in a UnicodeString
      Returns:
      the escaped or unescaped string
      Throws:
      XPathException - if there are invalid characters or escape sequences
    • 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(StringBuilder 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(String escaped, boolean isKey) throws XPathException
      Throws:
      XPathException
    • setFallbackFunction

      public void setFallbackFunction(Map<String,GroundedValue> options, XPathContext context) throws XPathException
      Throws:
      XPathException