Interface JSONContentHandler

  • All Known Implementing Classes:
    JSONDefaultHandler

    public interface JSONContentHandler
    This is the main interface to be implemented by an application wanting to receive JSON parsing events. An application can implement this interface and register the implementation with the JSONParser using the setContentHandler method.
    Author:
    Chris Burdess
    • Method Summary

      All Methods Instance Methods Abstract Methods Default Methods 
      Modifier and Type Method Description
      void booleanValue​(boolean value)
      Notifies of a JSON boolean value.
      void endArray()
      Indicates the end of a JSON array.
      void endObject()
      Indicates the end of a JSON object.
      void key​(java.lang.String key)
      Notifies of a key in a JSON object.
      default boolean needsWhitespace()
      Indicates whether this handler needs to receive whitespace events.
      void nullValue()
      Notifies of a JSON null value.
      void numberValue​(java.lang.Number number)
      Notifies of a JSON number.
      void setLocator​(JSONLocator locator)
      Receive an object that can be used to determine the current location during parsing.
      void startArray()
      Indicates the start of a JSON array.
      void startObject()
      Indicates the start of a JSON object.
      void stringValue​(java.lang.String value)
      Notifies of a JSON string.
      void whitespace​(java.lang.String whitespace)
      Notifies of whitespace in the underlying stream.
    • Method Detail

      • startObject

        void startObject()
                  throws JSONException
        Indicates the start of a JSON object.
        Throws:
        JSONException - the client may throw an exception during processing
      • endObject

        void endObject()
                throws JSONException
        Indicates the end of a JSON object.
        Throws:
        JSONException - the client may throw an exception during processing
      • startArray

        void startArray()
                 throws JSONException
        Indicates the start of a JSON array.
        Throws:
        JSONException - the client may throw an exception during processing
      • endArray

        void endArray()
               throws JSONException
        Indicates the end of a JSON array.
        Throws:
        JSONException - the client may throw an exception during processing
      • numberValue

        void numberValue​(java.lang.Number number)
                  throws JSONException
        Notifies of a JSON number.
        Parameters:
        number - the number parsed: may be an Integer, Long, or Double
        Throws:
        JSONException - the client may throw an exception during processing
      • stringValue

        void stringValue​(java.lang.String value)
                  throws JSONException
        Notifies of a JSON string.
        Parameters:
        value - the string value, unescaped and unquoted
        Throws:
        JSONException - the client may throw an exception during processing
      • booleanValue

        void booleanValue​(boolean value)
                   throws JSONException
        Notifies of a JSON boolean value.
        Parameters:
        value - the boolean value
        Throws:
        JSONException - the client may throw an exception during processing
      • nullValue

        void nullValue()
                throws JSONException
        Notifies of a JSON null value.
        Throws:
        JSONException - the client may throw an exception during processing
      • whitespace

        void whitespace​(java.lang.String whitespace)
                 throws JSONException
        Notifies of whitespace in the underlying stream. Note that whitespace between key strings and their associated colon, if present, will not be reported by this method.
        Parameters:
        whitespace - the whitespace contents as a string
        Throws:
        JSONException - the client may throw an exception during processing
      • key

        void key​(java.lang.String key)
          throws JSONException
        Notifies of a key in a JSON object. This is a string followed by a colon inside an object representation in the JSON source. It will always be associated with the most recent previous startObject event.
        Parameters:
        key - the key name
        Throws:
        JSONException - the client may throw an exception during processing
      • setLocator

        void setLocator​(JSONLocator locator)
        Receive an object that can be used to determine the current location during parsing. The locator allows the application to determine the end position of any parsing-related event, even if the parser is not reporting an error. Typically, the application will use this information for reporting its own errors (such as character content that does not match an application's business rules).
        Parameters:
        locator - the locator object
      • needsWhitespace

        default boolean needsWhitespace()
        Indicates whether this handler needs to receive whitespace events. By default, handlers do not need whitespace, which allows the parser to skip expensive string extraction for whitespace sequences. Implementations that need whitespace (e.g., for pretty-printing or preserving exact formatting) should override this to return true.
        Returns:
        true if this handler wants whitespace(String) to be called, false otherwise (default)