Hi there, is there a way to change the way an Enum is serialized / deserialized when you can't modify it? I want to change the way the deserialization works to transform an unknown enum value to "MyEnum.OTHER" instead of throwing an exception.
I implemented my own KSerializer(MyEnum), registered it in
instead of the serializer I registered. Is there a way to force the use of my serializer ?
✅ 1
e
ephemient
10/08/2025, 3:05 PM
Copy code
@Serializable
data class Foo(
// uses the default enum serializer
val myEnum1: MyEnum,
// uses the contextual serializer set up in the SerializersModule
@Contextual
val myEnum2: MyEnum,
// uses a specific serializer
@Serializable(with = MyEnumSerializer::class)
val myEnum3: MyEnum,
)
l
Lilian GALLON
10/08/2025, 3:08 PM
Thank you, turns out that my serializer generator did not add any annotations on the enum fields, so it kept using the built-in one. My bad, thank you for the clarifications 🙂