You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Value classes that implemnet sealed interfaces marked as @serializable cannot be decoded and will crash.
This is because the type of the sealed interface cannot be set during serialization.
To Reproduce
// SealedInterface.kt
@Serializable
sealedinterfaceSealedInterface
@Serializable
@JvmInline
value classValueClass(valvalue:String): SealedInterface
// App.ktval valueClass:ValueClass=ValueClass("value-class-value")
println("valueClass: $valueClass")
val valueClassString =Json.encodeToString(valueClass)
println(" encoded: $valueClassString")
// 💥 will be runtime error !println(" decoded: ${Json.decodeFromString<SealedInterface>(valueClassString).let { it to it::class }}")
Since ValueClasses inheriting from SealedInterface are inherently impossible to deserialize, it may be necessary to treat this as a compile-time error.