MapJsonReader

class MapJsonReader @JvmOverloads constructor(val root: Any?, pathRoot: List<Any> = emptyList()) : JsonReader

A JsonReader that can consumes ApolloJsonElement values as Json

To read from a okio.BufferedSource, see also BufferedSourceJsonReader

Parameters

root

the root object to read from

pathRoot

the path root to be prefixed to the returned path when calling getPath. Useful for buffer.

Constructors

Link copied to clipboard
constructor(root: Any?, pathRoot: List<Any> = emptyList())

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
val root: Any?

Functions

Link copied to clipboard
open override fun beginArray(): MapJsonReader

Consumes the next token from the JSON stream and asserts that it is the beginning of a new array.

Link copied to clipboard
open override fun beginObject(): MapJsonReader

Consumes the next token from the JSON stream and asserts that it is the beginning of a new object.

Link copied to clipboard

buffers the next Object. Has to be called in BEGIN_OBJECT position. The returned MapJsonReader can use MapJsonReader.rewind to read fields multiple times

Link copied to clipboard
open override fun close()
Link copied to clipboard
open override fun endArray(): MapJsonReader

Consumes the next token from the JSON stream and asserts that it is the end of the current array.

Link copied to clipboard
open override fun endObject(): MapJsonReader

Consumes the next token from the JSON stream and asserts that it is the end of the current object.

Link copied to clipboard
open override fun getPath(): List<Any>

Returns the current path of the JSON being read, as a List. The elements can either be Strings (names) or Integers (array indices).

Link copied to clipboard
open override fun hasNext(): Boolean

Returns true if the current array or object has another element.

Link copied to clipboard
open override fun nextBoolean(): Boolean

Returns the Token.BOOLEAN value of the next token, consuming it.

Link copied to clipboard
open override fun nextDouble(): Double

Returns the Token.NUMBER value of the next token, consuming it.

Link copied to clipboard
open override fun nextInt(): Int

Returns the Token.NUMBER value of the next token, consuming it.

Link copied to clipboard
open override fun nextLong(): Long

Returns the Token.NUMBER value of the next token, consuming it.

Link copied to clipboard
open override fun nextName(): String

Returns the next token Token.NAME, and consumes it.

Link copied to clipboard
open override fun nextNull(): Nothing?

Consumes the next token from the JSON stream and asserts that it is a literal null. Returns null.

Link copied to clipboard
open override fun nextNumber(): JsonNumber

Returns the Token.NUMBER value of the next token, consuming it.

Link copied to clipboard
open override fun nextString(): String

Returns the Token.STRING value of the next token, consuming it.

Link copied to clipboard
fun nextValue(): Any
Link copied to clipboard
fun <D : Operation.Data> JsonReader.parseResponse(operation: Operation<D>, requestUuid: Uuid? = null, customScalarAdapters: CustomScalarAdapters = CustomScalarAdapters.Empty, deferredFragmentIdentifiers: Set<DeferredFragmentIdentifier>? = null): ApolloResponse<D>

Reads a ApolloResponse from this. The caller is responsible for closing this.

Link copied to clipboard
open override fun peek(): JsonReader.Token

Returns the type of the next token without consuming it.

Link copied to clipboard

Returns the Kotlin representation of the given JsonReader

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
open override fun rewind()

Rewinds to the beginning of the current object.

Link copied to clipboard
open override fun selectName(names: List<String>): Int

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.

Link copied to clipboard
open override fun skipValue()

Skips the next value recursively. If it is an object or array, all nested elements are skipped.

Link copied to clipboard
fun <D : Operation.Data> JsonReader.toApolloResponse(operation: Operation<D>, requestUuid: Uuid? = null, customScalarAdapters: CustomScalarAdapters = CustomScalarAdapters.Empty, deferredFragmentIdentifiers: Set<DeferredFragmentIdentifier>? = null): ApolloResponse<D>

Reads a single ApolloResponse from this. Returns an error response if this contains more than one JSON response or trailing tokens. toApolloResponse takes ownership and closes this.