jsonkotlinklaxon

Parse JSON containing nested lists in Kotlin with Klaxon


I'm new to Kotlin and trying to parse list of lists in JSON:

data class Root (val lists: List<List<String>>)

val result = Klaxon().parse<Root>("""
{
    "lists": [["red", "green", "blue"]]
}
""")

But I get this runtime exception:

Exception in thread "main" java.lang.ClassCastException: sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl cannot be cast to java.lang.Class

It seems that Klaxon can't quite figure out List<List<String>>.

I also need this to work in general for nested collections:


Solution

  • This is fixed in Klaxon 2.1.11.