Closed valeriyo closed 1 week ago
This is caused by the fact that your ValueClass
is an inline class over Int
. There is simply nowhere to add type
, because Int is not an object. See https://github.com/Kotlin/kotlinx.serialization/issues/2049#issuecomment-1476647228
Describe the bug
SealedClassSerializer
doesn't serialize value subclasses into the expected structure, withtype
property. Instead it just dumps the raw value, which won't deserialize back!To Reproduce See test below
Expected behavior Instead of raw value, the resulting JSON should be of the same structure, as regular subclasses: "{\"type\":\".......\",\"value\":......}"
Environment
Android Studio Ladybug
@Serializable sealed interface Sealed {
@Serializable @SerialName("DataObject") data object DataObject : Sealed
@Serializable @SerialName("DataClass") data class DataClass(val code: Int) : Sealed
@Serializable @SerialName("ValueClass") @JvmInline value class ValueClass(val code: Int) : Sealed }
class SealedTest {
@Test fun test() { val serializer = Sealed.serializer()
} }