When it comes to Kotlin, result is now public final val result: Any? and it is super difficult to work with Any. Is there a way to use result as a Map and List as below?
for (item in result.get("foo").get("bar")) {
item.get("category")
}
If your type has always the same shape, you could add it on a new type in your schema.
Else you’ll have to cast. I have these extensions that I reuse in such cases:
inline fun <reified T> Any?.cast() = this as T
val Any?.asMap: Map<String, Any?>
get() = this.cast()
val Any?.asList: List<Any?>
get() = this.cast()
val Any?.asString: String
get() = this.cast()
Then you code becomes:
for (item in resulet.asMap.get("foo").asMap.get("bar").asList) {
item.asMap.get("category")
}
It’s a bit more verbose but there’s no silver bullet unfortunately