thevery
10/17/2018, 1:46 PM@Polymorphic
doesn't work with generics well?
class ParserTest {
open class Field
@Serializable data class FieldB(val a: String, val b: Int) : Field()
@Serializable data class FieldC(val a: String, val b: Int) : Field()
@Serializable data class Data(@Polymorphic val a: List<Field>)
@Test
fun testPoly() {
val obj = JSON.parse<Data>("""{"a":[{a:"a", b: 1}]}""")
println("obj = ${obj}")
}
}
produces
java.lang.IllegalArgumentException: JSON at 6: Expected '[, kind: kotlinx.serialization.UnionKind$POLYMORPHIC@33e5ccce'
sandwwraith
10/17/2018, 2:45 PM"""{"a":[["FieldC", {a:"a", b: 1}]]}"""
sandwwraith
10/17/2018, 2:46 PMval a: List<@Polymorphic Field>
, but it doesn’t matter for nowthevery
10/17/2018, 2:51 PM{"a":[{a:"a", b: 1}]}
and
{"a":[{a:"a", c: "1"}]}
sandwwraith
10/17/2018, 2:55 PM