Class JSONEventReader
java.lang.Object
com.leastfixedpoint.json.JSONEventReader
SAX-style event-emitting JSON parser. Only needed in advanced situations. Usually,
JSONReader
will
be what you're looking for.
If you do decide you want SAX-style events rather than finished, ready-to-use JSON-representing objects from
JSONReader.read()
or JSONReader.readValue()
, then instantiate this class and call
next()
repeatedly until you're done or it returns null. It will return tokens as follows:
- Strings, numbers, booleans, and null JSON values are returned directly, following the type mapping
documented in the class comment for
JSONReader
. - An object will be presented as
JSONReader.Lexeme.OBJECT_START
. Subsequent calls to next() will alternate between returning keys (strings) and values (possibly complex token sequences) until the object is closed byJSONReader.Lexeme.OBJECT_END
. - Similarly, an array appears as
JSONReader.Lexeme.ARRAY_START
followed by values (as possibly complex token sequences) until the end of the array, signalled byJSONReader.Lexeme.ARRAY_END
.
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected JSONReader
protected JSONEventReader.State
protected List
<JSONEventReader.State> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
Returns true iff the parser is not mid-way through some object; that is, we are at a boundary between JSON values.protected void
gotoState
(JSONEventReader.State newState) protected void
maybeEnterNested
(Object token) next()
Yields the next JSON token.protected void
pop()
protected void
pushAndGoto
(JSONEventReader.State newState)
-
Field Details
-
jsonReader
-
stateStack
-
state
-
-
Constructor Details
-
JSONEventReader
-
-
Method Details
-
next
Yields the next JSON token. Returns null at the end of the input (and thus differs from the behaviour ofJSONReader.nextLexeme()
).- Throws:
IOException
-
atBoundary
public boolean atBoundary()Returns true iff the parser is not mid-way through some object; that is, we are at a boundary between JSON values. -
maybeEnterNested
- Throws:
JSONSyntaxError
-
gotoState
-
pushAndGoto
-
pop
protected void pop()
-