Zyle Moore
12/27/2025, 8:21 AMvalue class, I get an error saying Expected JsonObject, but had JsonLiteral as the serialized body of kotlinx.serialization.Polymorphic<Name> at element: $.name. If I switch it to a data class it works better. MVCE here: https://pl.kotl.in/ojKxHZshWZyle Moore
12/27/2025, 8:26 AMinterface Name
interface Text : Name
@JvmInline
@Serializable
value class SerializableText(val string: String) : Text
@Serializable
data class SerializablePilot(val name: Name)
val testPilot = SerializablePilot(SerializableText("asdf"))
This serializes to
{
"type": "games.studiohummingbird.voyd.pilot.SerializablePilot",
"name": "asdf"
}Zyle Moore
12/27/2025, 8:29 AMSerializersModule {
polymorphic(Name::class) {
subclass(SerializableText::class)
}
polymorphic(Text::class) {
subclass(SerializableText::class)
}
}Zyle Moore
12/27/2025, 8:33 AMdata class serialization is a bit bulkier
{
"type": "games.studiohummingbird.voyd.pilot.SerializablePilot",
"name": {
"type": "games.studiohummingbird.skhema.datatypes.serializable.SerializableText",
"string": "asdf"
}
}Adam S
12/29/2025, 9:43 AMval name: Name, it sees that Name is an interface, and so it needs the JSON to have a "type": "..." property to determine which Name implementation to decode.
But the actual value is just a string, because InlineSerializableText is a value class, so it can't have a "type" property.Adam S
12/29/2025, 9:51 AM