Polymorphic serializer was not found for class discriminator 'batteryPercentage', JSON input: {"name":"batteryPercentage","value":70}
Copy code
@JsonClassDiscriminator("name")
interface DeviceAttribute
@Serializable
data class Device(
val id: String,
val name: String,
val icon: String,
val iconOptions: List<String>,
val attributes: List<DeviceAttribute> = emptyList(),
val profiles: List<ActiveProfileMode>?,
)
@Serializable
@SerialName("batteryPercentage")
data class BatteryPercentage(val value: Int) : DeviceAttribute
What am I missing here?
e
Emil Kantis
05/31/2022, 2:13 PM
Iirc you need to use a sealed class hierarchy to get automatic polymorphic serialization
r
rocketraman
05/31/2022, 2:14 PM
That's open polymorphism, as your base class is an interface. You need to register your subsclasses in a