Open uliSchuster opened 1 year ago
The BoxedSerializer
leads to an internal error because it expects that validationSerializer
property would be provided. Because enums do not have any type parameters, there is nothing to insert. We should add proper diagnostic there
Regardless stack overflow with surrogate serializer — can you please show an example?
I don't think that now it is possible to encode enums polymorphically (also #2164) unless you write a fully custom serializer for sealed interface Validation
. Alternatively, you can try to change all enums into sealed classes, and enum entries — to object
s, as objects mix well into sealed hierarchies.
Describe the bug
I have the following sealed interface (simplified example):
...which is implemented by several enums - each one for a particular application. For example:
I want to use this enum polymorphically in serializable API types, like so:
Out-of-the-box, this setup does not work, because enums are serialized as primitive types, without a
type
field for polymorphic serialization. I tried several other attempts:To Reproduce
Surrogate serialization in a generic wrapper class also fails with an internal compiler error:
Expected behavior
What I would like to get as output (JSON example):
or (closer to the standard)
How would a semi-custom or (if necessary) full-custom serializer look like?
Thanks for your help!
Environment