Tomas Haddad
02/14/2026, 10:17 AM@Serializable
data class EnumPair<T>{
val label: String
val value: T,
} where T : Enum<T>
When I have two fields on a class that use this generic, say:
@Serializable
data class Example(
val helloWorld: EnumPair<HelloWorld>, // an enum of Hello, World
val fooBar: EnumPair<FooBar> // an enum of Foo, Bar
)
When I create a schema for Example using Avro.default.schema(Example.serializer()), the second field incorrectly refers back to the first generated enum even though its values are different:
{
"name": "helloWorld",
"type": {
"type": "record",
"name": "EnumPair",
"fields": [
{
"name": "label",
"type": "string"
}, {
"name": "value",
"type": {
"type": "enum",
"name": "FooBar",
"symbols": ["Hello", "World"]
}
}
]
}
}, {
"name": "fooBar",
"type": "EnumPair"
}
Is this a problem solveable with a custom kotlinx serialiser? I'm thinking the serialiser could extract the class name of the generic T but I can't seen to write anything that works. I'm relatively new at serialisation/deserialisation so any advice is welcome (including telling me I'm doing something silly 😅)