Class JsonHandler<A,O>
- Type Parameters:
A
- The type of handlers used for JSON arraysO
- The type of handlers used for JSON objects
- Direct Known Subclasses:
JsonHandlerDelegator
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:
["lorem ipsum"] ^ ^ startString endString
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.
- See Also:
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Indicates the end of an array in the JSON input.void
endArrayValue
(A array) Indicates the end of an array element in the JSON input.void
endBoolean
(boolean value) Indicates the end of a boolean literal (true
orfalse
) in the JSON input.void
endNull()
Indicates the end of anull
literal in the JSON input.void
Indicates the end of a number in the JSON input.void
Indicates the end of an object in the JSON input.void
endObjectName
(O object, String name) Indicates the end of an object member name in the JSON input.void
endObjectValue
(O object, String name) Indicates the end of an object member value in the JSON input.void
Indicates the end of a string in the JSON input.protected Location
Returns the current parser location.Indicates the beginning of an array in the JSON input.void
startArrayValue
(A array) Indicates the beginning of an array element in the JSON input.void
Indicates the beginning of a boolean literal (true
orfalse
) in the JSON input.void
Indicates the beginning of anull
literal in the JSON input.void
Indicates the beginning of a number in the JSON input.Indicates the beginning of an object in the JSON input.void
startObjectName
(O object) Indicates the beginning of the name of an object member in the JSON input.void
startObjectValue
(O object, String name) Indicates the beginning of the name of an object member in the JSON input.void
Indicates the beginning of a string in the JSON input.
-
Constructor Details
-
JsonHandler
public JsonHandler()
-
-
Method Details
-
getLocation
Returns the current parser location.- Returns:
- the current parser location
-
startNull
public void startNull()Indicates the beginning of anull
literal in the JSON input. This method will be called when reading the first character of the literal. -
endNull
public void endNull()Indicates the end of anull
literal in the JSON input. This method will be called after reading the last character of the literal. -
startBoolean
public void startBoolean()Indicates the beginning of a boolean literal (true
orfalse
) in the JSON input. This method will be called when reading the first character of the literal. -
endBoolean
public void endBoolean(boolean value) Indicates the end of a boolean literal (true
orfalse
) in the JSON input. This method will be called after reading the last character of the literal.- Parameters:
value
- the parsed boolean value
-
startString
public void startString()Indicates the beginning of a string in the JSON input. This method will be called when reading the opening double quote character ('"'
). -
endString
Indicates the end of a string in the JSON input. This method will be called after reading the closing double quote character ('"'
).- Parameters:
string
- the parsed string
-
startNumber
public void startNumber()Indicates the beginning of a number in the JSON input. This method will be called when reading the first character of the number. -
endNumber
Indicates the end of a number in the JSON input. This method will be called after reading the last character of the number.- Parameters:
string
- the parsed number string
-
startArray
Indicates the beginning of an array in the JSON input. This method will be called when reading the opening square bracket character ('['
).This method may return an object to handle subsequent parser events for this array. This array handler will then be provided in all calls to
startArrayValue()
,endArrayValue()
, andendArray()
for this array.- Returns:
- a handler for this array, or
null
if not needed
-
endArray
Indicates the end of an array in the JSON input. This method will be called after reading the closing square bracket character (']'
).- Parameters:
array
- the array handler returned fromstartArray()
, ornull
if not provided
-
startArrayValue
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 thestart
method for the specific element type (startString()
,startNumber()
, etc.).- Parameters:
array
- the array handler returned fromstartArray()
, ornull
if not provided
-
endArrayValue
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 theend
method for the specific element type (likeendString()
,endNumber()
, etc.).- Parameters:
array
- the array handler returned fromstartArray()
, ornull
if not provided
-
startObject
Indicates the beginning of an object in the JSON input. This method will be called when reading the opening curly bracket character ('{'
).This method may return an object to handle subsequent parser events for this object. This object handler will be provided in all calls to
startObjectName()
,endObjectName()
,startObjectValue()
,endObjectValue()
, andendObject()
for this object.- Returns:
- a handler for this object, or
null
if not needed
-
endObject
Indicates the end of an object in the JSON input. This method will be called after reading the closing curly bracket character ('}'
).- Parameters:
object
- the object handler returned fromstartObject()
, or null if not provided
-
startObjectName
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.- Parameters:
object
- the object handler returned fromstartObject()
, ornull
if not provided
-
endObjectName
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.- Parameters:
object
- the object handler returned fromstartObject()
, or null if not providedname
- the parsed member name
-
startObjectValue
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.- Parameters:
object
- the object handler returned fromstartObject()
, ornull
if not providedname
- the member name
-
endObjectValue
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 theend
method for the specific member type (likeendString()
,endNumber()
, etc.).- Parameters:
object
- the object handler returned fromstartObject()
, or null if not providedname
- the parsed member name
-