commonMain.com.apollographql.apollo.api.json.MapJsonReader.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of apollo-api-jvm Show documentation
Show all versions of apollo-api-jvm Show documentation
Apollo GraphQL API classes
The newest version!
package com.apollographql.apollo.api.json
import com.apollographql.apollo.api.json.BufferedSourceJsonReader.Companion.INITIAL_STACK_SIZE
import com.apollographql.apollo.api.json.MapJsonReader.Companion.buffer
import com.apollographql.apollo.api.json.internal.toDoubleExact
import com.apollographql.apollo.api.json.internal.toIntExact
import com.apollographql.apollo.api.json.internal.toLongExact
import com.apollographql.apollo.exception.JsonDataException
import kotlin.jvm.JvmOverloads
/**
* A [JsonReader] that can consumes [ApolloJsonElement] values as Json
*
* To read from a [okio.BufferedSource], see also [BufferedSourceJsonReader]
*
* @param root the root object to read from
* @param pathRoot the path root to be prefixed to the returned path when calling [getPath]. Useful for [buffer].
*/
class MapJsonReader
@JvmOverloads
constructor(
val root: Any?,
private val pathRoot: List = emptyList(),
) : JsonReader {
private var peekedToken: JsonReader.Token
/**
* Depending on what [peekedToken] is, [peekedData] can be safely cast to a Map, Entry
* or other values
*/
private var peekedData: Any? = null
/**
* Can contain either:
* - an Int representing the next index to be read in a List
* - a String representing the current key to be read in a Map
* - null if peekedToken is BEGIN_OBJECT
*/
private var path = arrayOfNulls(INITIAL_STACK_SIZE)
/**
* The current object memorized in case we need to rewind
*/
private var containerStack = arrayOfNulls
© 2015 - 2025 Weber Informatics LLC | Privacy Policy