Sebastian Schuberth

    4 months ago
    I'm trying to write a custom serializer for
    , 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
    to create an instance of the
    from a string which that enum uses in its overridden
    Basically something like this:
    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