fromJson

abstract fun fromJson(reader: JsonReader, customScalarAdapters: CustomScalarAdapters): T

Deserializes the given Json to the expected Kotlin type.

implementations may throw com.apollographql.apollo3.exception.JsonEncodingException or com.apollographql.apollo3.exception.JsonDataException on unexpected incoming data

Example:

override fun fromJson(reader: JsonReader, customScalarAdapters: CustomScalarAdapters): LocalDateTime {
return LocalDateTime.parse(reader.nextString()!!)
}

Alternatively, you can use the built-in AnyAdapter to simplify the parsing loop:

override fun fromJson(reader: JsonReader, customScalarAdapters: CustomScalarAdapters): GeoPoint {
val map = AnyAdapter.fromJson(reader) as Map<String, Double>

return GeoPoint(map["lat"]!!, map["lon"]!!)
}