https://kotlinlang.org logo
Title
t

Thiago Nerys

03/03/2020, 3:02 PM
fun <http://java.io|java.io>.InputStream.extractSummary(): String =
    ((JsonSlurper().parse(this) as Map<String, Any>)["fields"] as Map<String, Any>)["summary"] as String
I looked around a lot, couldn't find a way to make this code block simpler. Would like to do something similar to Groovy, which allows me to call just
this.fields.summary
. Any ideas?
r

ribesg

03/03/2020, 3:09 PM
That’s because Groovy isn’t really typed. Try to parse your InputStream as an actual model instead of just a map
t

Thiago Nerys

03/03/2020, 3:11 PM
JsonSlurper won't give me that option and I don't want to add a library to do that
m

mbonnin

03/03/2020, 3:37 PM
You could add extension functions on
Map
and
InputStream
so that it becomes
this.parse().getObject("fields").getString("summary")
👍 1