ankushg
08/18/2021, 7:14 PMtype
as the discriminator, but we'd also like to have a val type
inside the deserialized object, containing the same content as type
from the serialization logic.
I imagine that the tricky part here would be that there's no guarantees that the val type
would always line up with the class discriminator when serializing or mutating a deserialized class?CLOVIS
08/18/2021, 7:45 PM@Serializable
sealed class Foo(
@Transient val _type: String
)
@Serializable
class A(...) : Foo("A")
ephemient
08/18/2021, 8:55 PM@Serializable
sealed class Foo {
abstract val type: String
}
@Serializable
sealed class A : Foo() {
override val type: String
get() = serializer().descriptor.serialName
}
Richard Gomez
08/18/2021, 8:59 PMby lazy { }
be preferable to get()
? I assume the latter would instantiate a new serializer each time it's called, but it may be a singleton.ephemient
08/18/2021, 9:08 PM