api / tv.twelvetone.json / JsonHandler

JsonHandler

abstract class JsonHandler<A, O>

A handler for parser events. Instances of this class can be given to a JsonParser. The parser will then call the methods of the given handler while reading the input.

The default implementations of these methods do nothing. Subclasses may override only those methods they are interested in. They can use getLocation() to access the current character position of the parser at any point. The start* methods will be called while the location points to the first character of the parsed element. The end* methods will be called while the location points to the character position that directly follows the last character of the parsed element. Example:

Subclasses that build an object representation of the parsed JSON can return arbitrary handler objects for JSON arrays and JSON objects in .startArray and .startObject. These handler objects will then be provided in all subsequent parser events for this particular array or object. They can be used to keep track the elements of a JSON array or object.

Parameters

Parameters

See Also

JsonParser

Constructors

<init>

JsonHandler()

A handler for parser events. Instances of this class can be given to a JsonParser. The parser will then call the methods of the given handler while reading the input.

Properties

location

val location: Location

Returns the current parser location.

Functions

endArray

open fun endArray(array: A?): Unit

Indicates the end of an array in the JSON input. This method will be called after reading the closing square bracket character (']').

endArrayValue

open fun endArrayValue(array: A?): Unit

Indicates the end of an array element in the JSON input. This method will be called after reading the last character of the element value, just after the end method for the specific element type (like endString(), endNumber(), etc.).

endBoolean

open fun endBoolean(value: Boolean): Unit

Indicates the end of a boolean literal (true or false) in the JSON input. This method will be called after reading the last character of the literal.

endNull

open fun endNull(): Unit

Indicates the end of a null literal in the JSON input. This method will be called after reading the last character of the literal.

endNumber

open fun endNumber(string: String): Unit

Indicates the end of a number in the JSON input. This method will be called after reading the last character of the number.

endObject

open fun endObject(object: O?): Unit

Indicates the end of an object in the JSON input. This method will be called after reading the closing curly bracket character ('}').

endObjectName

open fun endObjectName(object: O?, name: String): Unit

Indicates the end of an object member name in the JSON input. This method will be called after reading the closing quote character ('"') of the member name.

endObjectValue

open fun endObjectValue(object: O?, name: String): Unit

Indicates the end of an object member value in the JSON input. This method will be called after reading the last character of the member value, just after the end method for the specific member type (like endString(), endNumber(), etc.).

endString

open fun endString(string: String): Unit

Indicates the end of a string in the JSON input. This method will be called after reading the closing double quote character ('"').

startArray

open fun startArray(): A?

Indicates the beginning of an array in the JSON input. This method will be called when reading the opening square bracket character ('[').

startArrayValue

open fun startArrayValue(array: A?): Unit

Indicates the beginning of an array element in the JSON input. This method will be called when reading the first character of the element, just before the call to the start method for the specific element type (.startString, .startNumber, etc.).

startBoolean

open fun startBoolean(): Unit

Indicates the beginning of a boolean literal (true or false) in the JSON input. This method will be called when reading the first character of the literal.

startNull

open fun startNull(): Unit

Indicates the beginning of a null literal in the JSON input. This method will be called when reading the first character of the literal.

startNumber

open fun startNumber(): Unit

Indicates the beginning of a number in the JSON input. This method will be called when reading the first character of the number.

startObject

open fun startObject(): O?

Indicates the beginning of an object in the JSON input. This method will be called when reading the opening curly bracket character ('{').

startObjectName

open fun startObjectName(object: O?): Unit

Indicates the beginning of the name of an object member in the JSON input. This method will be called when reading the opening quote character ('"') of the member name.

startObjectValue

open fun startObjectValue(object: O?, name: String): Unit

Indicates the beginning of the name of an object member in the JSON input. This method will be called when reading the opening quote character ('"') of the member name.

startString

open fun startString(): Unit

Indicates the beginning of a string in the JSON input. This method will be called when reading the opening double quote character ('"').