I'm trying to write a custom serializer for `Enum`...
# serialization
s
I'm trying to write a custom serializer for
Enum
, 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?
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
.
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
}