- 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
Modifier and TypeMethodDescriptionvoidbooleanValue(boolean value) Notifies of a JSON boolean value.voidendArray()Indicates the end of a JSON array.voidIndicates the end of a JSON object.voidNotifies of a key in a JSON object.default booleanIndicates whether this handler needs to receive whitespace events.voidNotifies of a JSON null value.voidnumberValue(Number number) Notifies of a JSON number.voidsetLocator(JSONLocator locator) Receive an object that can be used to determine the current location during parsing.voidIndicates the start of a JSON array.voidIndicates the start of a JSON object.voidstringValue(String value) Notifies of a JSON string.voidwhitespace(String whitespace) Notifies of whitespace in the underlying stream.
-
Method Details
-
startObject
Indicates the start of a JSON object.- Throws:
JSONException- the client may throw an exception during processing
-
endObject
Indicates the end of a JSON object.- Throws:
JSONException- the client may throw an exception during processing
-
startArray
Indicates the start of a JSON array.- Throws:
JSONException- the client may throw an exception during processing
-
endArray
Indicates the end of a JSON array.- Throws:
JSONException- the client may throw an exception during processing
-
numberValue
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
Notifies of a JSON string.- Parameters:
value- the string value, unescaped and unquoted- Throws:
JSONException- the client may throw an exception during processing
-
booleanValue
Notifies of a JSON boolean value.- Parameters:
value- the boolean value- Throws:
JSONException- the client may throw an exception during processing
-
nullValue
Notifies of a JSON null value.- Throws:
JSONException- the client may throw an exception during processing
-
whitespace
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
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
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)
-