Nikky
01/14/2022, 11:38 AM"{"type": "A", ...}"
into a PolymorphicType.A.serializer()
it fails with a Unexpected JSON token at offset 11: Encountered an unknown key 'type'.
is there a way to skip that.. while also not adding type
as a property to the class (because that creates other issue)
or using ignoreUnknownKeys = true
because there could be other.. issues ?
oone way i found was to use
val a = Json.decodeFromString(PolymorphicType.serializer(), jsonString) as PolymorphicType.A
but that means that there is no way to use this.. except for encoding and decoding using the polymorphic types.. or you wil lose the type
propertiesEugen Martynov
01/14/2022, 2:10 PMPolymorphicType.serializer()
insteadEugen Martynov
01/14/2022, 2:11 PMignoreUnknownKeys = true
for your testDominaezzz
01/14/2022, 5:44 PMtype
if you know the specific base class. So type
will be an unknown key.
Sadly, kotlinx.serialization can't really be smart about this because a class could be implementing multiple interfaces, each with their own discriminator.Nikky
01/14/2022, 7:08 PM"type"
key present
i guess i forgot to mention that requirementNikky
01/14/2022, 7:09 PMoverride val type = "Point"
and not conflict with it ?Dominaezzz
01/14/2022, 7:44 PMNikky
01/15/2022, 12:44 PMNikky
01/15/2022, 12:45 PM@SerialName
and a @Transient val type: String
to make it somehow work