JsonReader
Reads a JSON RFC 7159 encoded value as a stream of tokens.
This stream includes both literal values (strings, numbers, booleans, and nulls) as well as the begin and end delimiters of objects and arrays.
The tokens are traversed in depth-first order, the same order that they appear in the JSON document. Within JSON objects, name/value pairs are represented by a single token.
Each {@code JsonReader} may be used to read a single JSON stream. Instances of this class are not thread safe.
Json doesn't have int, long, double values. Only string and number. That means nextInt(), nextDouble(), nextLong() and nextNumber() will coerce the Json value into the expected type or throw if the conversion is not possible or loses precision.
BufferedSourceJsonReader can parse longs without having to buffer so when possible, prefer nextLong() over nextInt()
Note: This interface was originally from Moshi and has been tweaked to better match the GraphQL use cases
Types
Functions
Consumes the next token from the JSON stream and asserts that it is the beginning of a new array.
Consumes the next token from the JSON stream and asserts that it is the beginning of a new object.
Consumes the next token from the JSON stream and asserts that it is the end of the current array.
Consumes the next token from the JSON stream and asserts that it is the end of the current object.
Returns the Token.BOOLEAN value of the next token, consuming it.
Returns the Token.NUMBER value of the next token, consuming it.
Returns the Token.NUMBER value of the next token, consuming it.
Returns the Token.NUMBER value of the next token, consuming it.
Returns the next token Token.NAME, and consumes it.
Returns the Token.NUMBER value of the next token, consuming it.
Returns the Token.STRING value of the next token, consuming it.
Returns the type of the next token without consuming it.
Reset the current object so that selectName start returning names again
An optimized way to retrieve the nextName when the candidates and their order is known. selectName maintains the current index in the list and saves having to string compare nextName to every candidate.
Inheritors
Extensions
buffers the next Object. Has to be called in BEGIN_OBJECT
position. The returned MapJsonReader can use MapJsonReader.rewind to read fields multiple times
Reads the reader and maps numbers to the closest representation possible in that order: