Is there a way to deserialize `dynamic` into a sea...
# serialization
a
Is there a way to deserialize
dynamic
into a sealed (polymorphic) class using
DynamicObjectParser
, use a different mechanism than the normal
classDiscriminator=SerialName
to determine which concrete type is selected? For context, I'm consuming
dynamic
json objects from an external source (which will be very very hard to change to provide a
classDiscriminator
along with everything). They've got typescript definitions such as:
Copy code
type AttributeContentType =
  | {
      word: String;
    }
  | {
      definition: String;
    };
I've represented this in Kotlin as:
Copy code
sealed class AttributeContentType
data class WordAttributeContent(val word: String) : AttributeContentType()
data class DefinitionAttributeContent(val definition: String) : AttributeContentType()
In the above case, I'd want something like
js("""{ word: "foo" }""")
to be deserialized into a
WordAttributeContent
by (somehow) seeing that it has the
word
field.