BearDev
05/06/2019, 6:42 AM@Serializable
@Polymorphic
data class JsonMessage(
@Polymorphic val command: JsonCommand
)
@Serializable
@Polymorphic
open class JsonCommand
@Serializable
@Polymorphic
data class NewL2SnapCommand(
val symbol: String
) : JsonCommand()
@UnstableDefault
fun main() {
val message = JsonMessage(
NewL2SnapCommand(
symbol = "ABC"
)
)
val snapJson = Json.stringify(JsonMessage.serializer(), message)
println(snapJson)
}
This results in
Exception in thread "main" kotlinx.serialization.SerializationException: class jsonApi.NewL2SnapCommand is not registered for polymorphic serialization in the scope of class jsonApi.JsonCommand
The documentation for this is kinda sparse since it's a new feature, so any help would be appreciated.