In authoring new custom scalar adapters, I now notice that the fromJson reader value is a json object when the value is from the server and alternatively a json string if that same value is fetched instead from the cache. Is this the expected behavior?
If I check for the representation, I seem to be able to handle it.
// GeoJSONGeometry
// A geometry encoded as any valid GeoJSON geometry type. See https://geojson.org.
val geometryAdapter = object : Adapter<Geometry> {
override fun fromJson(reader: JsonReader, customScalarAdapters: CustomScalarAdapters): Geometry {
val peek = reader.peek()
if (peek == JsonReader.Token.STRING) {
reader.nextName()
val geometry = reader.nextString()!!
return try {
Polygon.fromJson(geometry)
...
val map = AnyAdapter.fromJson(reader, customScalarAdapters) as Map<*, *>
return when (map["type"]) {
"Polygon" -> {
val coordinates = (map["coordinates"] as List<List<List<Double>>>).map {
it.map { point -> Point.fromLngLat(point[0], point[1]) }
}
Polygon.fromLngLats(coordinates)
}
...
}
}