klaxon
klaxon copied to clipboard
Could not parse data for class with generic field
Klaxon couldn't parse data for class with generic field.
data class A (val a: Int)
data class Parse<T>(val a: T)
Klaxon().parse<Parse<A>>("""{"a":{"a":1}}""")
causes
java.lang.ClassCastException: kotlin.reflect.jvm.internal.KTypeParameterImpl cannot be cast to kotlin.reflect.KClass
at com.beust.klaxon.Annotations$Companion.findJsonPaths(Annotations.kt:63)
at com.beust.klaxon.Annotations$Companion.findJsonPaths(Annotations.kt:56)
at com.beust.klaxon.Klaxon.parser(Klaxon.kt:141)
at com.beust.klaxon.Klaxon.parser$default(Klaxon.kt:140)
...
Tested with Klaxon 3.0.5.
Any update here? Having similar issue
+1
Looking into this.
Right now I'm struggling trying to recover the fact that T
's effective type is A
, and I can't seem to be able to get this from kotlin-reflect
so far.
Any news? Or maybe workaround ideas? I tried to do something wiht TypeAdapter
, but lost the battle with Kotlin :(
It seems its cause is type erasure which is the feature of JVM. It may need some different approach to resolve this issue.