Hi, it is possible to deserialize enum with unknow...
# serialization
m
Hi, it is possible to deserialize enum with unknown value? This code works fine in most case scenario but when my
MyEnum
has annotated field like this
@SerialName(value="very_long_long_name") NAME
it doesn't. Is there any way to access SerialName in KSerializer?
Copy code
override fun deserialize(decoder: Decoder): MyEnum {
    return MyEnum.values().find { it.name == decoder.decodeString() }
        ?: MyEnum.UNKNOWN
}
g
If you use JVM/Android :
Copy code
MyEnum::class.annotations.filterIsInstance<SerialName>().first().value
m
yeah it kinda works but uses reflection
g
Oh and also this approach, much better I presume
MyClass.serializer().descriptor.serialName
1