fromJson
open override fun fromJson(reader: JsonReader, customScalarAdapters: CustomScalarAdapters): Optional.Present<T>
Deserializes the given Json to the expected Kotlin type.
implementations may throw com.apollographql.apollo.exception.JsonEncodingException or com.apollographql.apollo.exception.JsonDataException on unexpected incoming data
Example:
override fun fromJson(reader: JsonReader, customScalarAdapters: CustomScalarAdapters): LocalDateTime {
return LocalDateTime.parse(reader.nextString()!!)
}
Content copied to clipboard
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"]!!)
}
Content copied to clipboard