hi, how can I choose a type based on a string para...
# serialization
n
hi, how can I choose a type based on a string parameter, for example I have such object for type A:
Copy code
{
  "type": "A",
  "field": "foo"
}
and such for type B:
Copy code
{
  "type": "B",
  "foo": "bar"
}
how to differentiate
@Serializable
classes based on the
type
field? the classes I currently have are as follows:
Copy code
@Serializable
sealed class Message {
    @Serializable data class A(field: String, type: String): Message()
    @Serializable data class B(foo: String, type: String): Message()
}
d
you have to specify
classDiscriminator
1
actually it defaults to
type
anyway
n
thanks, will try!
worked fine