https://kotlinlang.org logo
s

Stefan Beyer

06/18/2020, 9:51 AM
Does anyone have an idea why this happens?
Copy code
inline fun <reified T> ObjectMapper.read(json: String) = readValue<T>(json)
inline fun <reified T> ObjectMapper.readList(json: String) = read<List<T>>(json)

val mapper = ObjectMapper().registerKotlinModule() // fasterxml.jackson
data class Person(val name: String, val role: String)
val json = """[{"name":"Alice","role":"transmitter"},{"name":"Bob","role":"receiver"}]"""

val value1 = mapper.read<List<Person>>(json)
val value2 = mapper.readList<Person>(json)
println(value1) // value1 is a List<Person>
println(value2) // value2 is a List<Map<String, Any>>
When composing a reified type through multiple inline functions, the generic part seems to get gobbled up by the erasure, like it wasn't reified...
s

spand

06/18/2020, 9:58 AM
s

Stefan Beyer

06/18/2020, 10:03 AM
wow, I did not suspect this to be a long standing issue o_O thanks @spand for pointing to the issue 🙂
2 Views