JsonWriter
Writes a JSON RFC 7159 encoded value to a stream, one token at a time.
The stream includes both literal values (strings, numbers, booleans and nulls) as well as the begin and end delimiters of objects and arrays.
Encoding JSON
To encode your data as JSON, create a new JsonWriter
. Each JSON document must contain one top-level array or object. Call methods on the writer as you walk the structure's contents, nesting arrays and objects as necessary:
To write
arrays
, first call beginArray. Write each of the array's elements with the appropriate value. Finally close the array using endArray.To write
objects
, first call beginObject. Write each of the object's properties by alternating calls to name with the property's value. Write property values with the appropriate value method or by nesting other objects or arrays. Finally close the object using endObject.
Each JsonWriter
may be used to write a single JSON stream. Instances of this class are not thread safe. Calls that would result in a malformed JSON string will fail with an IllegalStateException.
Note: This interface was originally from Moshi and has been tweaked to better match the GraphQL use cases such as the absence of arbitrary precision and the presence of the Upload
Functions
Begins encoding a new array. Each call to this method must be paired with a call to endArray.
Begins encoding a new object. Each call to this method must be paired with a call to endObject.
Ends encoding the current array.
Ends encoding the current object.
Encodes the property name.
Encodes null
.
Encodes a Upload.
Encodes number value
.
Encodes boolean value
.
Encodes a finite double value
.
Encodes int value
.
Encodes long value
.
Encodes the literal string value
, or null to encode a null literal.