, the "common base class of all enum classes", but I'm struggling with the syntax for the generic type parameter. Has some done this successfully?
Sebastian Schuberth
05/02/2022, 4:58 PM
In particular, I'm struggling with overriding
deserialize
to create an instance of the
Enum
from a string which that enum uses in its overridden
toString
.
Sebastian Schuberth
05/02/2022, 5:00 PM
Basically something like this:
Copy code
@Serializer(Enum::class)
class EnumSerializer<E : Enum<E>> : KSerializer<E> {
override fun serialize(encoder: Encoder, value: E) = encoder.encodeString(value.toString())
override val descriptor: SerialDescriptor
get() = TODO("Not yet implemented")
override fun deserialize(decoder: Decoder) = // find the enum that uses decoder.decodeString() in its toString() here
}