Class JsonHandler<A,O>
- java.lang.Object
-
- com.restfb.json.JsonHandler<A,O>
-
- Type Parameters:
A
- The type of handlers used for JSON arraysO
- The type of handlers used for JSON objects
public abstract class JsonHandler<A,O> extends Object
A handler for parser events. Instances of this class can be given to aJsonParser
. 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. Thestart*
methods will be called while the location points to the first character of the parsed element. Theend*
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()
andstartObject()
. 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:
JsonParser
-
-
Constructor Summary
Constructors Constructor Description JsonHandler()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
endArray(A array)
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
endNumber(String string)
Indicates the end of a number in the JSON input.void
endObject(O object)
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
endString(String string)
Indicates the end of a string in the JSON input.protected Location
getLocation()
Returns the current parser location.A
startArray()
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
startBoolean()
Indicates the beginning of a boolean literal (true
orfalse
) in the JSON input.void
startNull()
Indicates the beginning of anull
literal in the JSON input.void
startNumber()
Indicates the beginning of a number in the JSON input.O
startObject()
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
startString()
Indicates the beginning of a string in the JSON input.
-
-
-
Constructor Detail
-
JsonHandler
public JsonHandler()
-
-
Method Detail
-
getLocation
protected Location 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
public void endString(String string)
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
public void endNumber(String string)
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
public A 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
public void endArray(A array)
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
public void startArrayValue(A array)
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
public void endArrayValue(A array)
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
public O 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
public void endObject(O object)
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
public void startObjectName(O object)
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
public void endObjectName(O object, String name)
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
public void startObjectValue(O object, String name)
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
public void endObjectValue(O object, String name)
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
-
-