Hi all :wave: I hope this question belongs in this...
# serialization
t
Hi all 👋 I hope this question belongs in this channel sweating I have a simple class that I want to serialise with Avro4k:
Copy code
@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:
Copy code
@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:
Copy code
{
    "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 😅)