It seems `JsonClassDiscriminator` doesn’t work on...
# serialization
a
It seems
JsonClassDiscriminator
doesn’t work on interfaces. The only way I can get polymorphic serialisation/deserialisation to work with interfaces is to register a polymorphic serialiser for it manually (as the docs specify). This ignores
JsonClassDiscriminator
though, it only seems to work when the discriminator is the default key:
type
e
@JsonClassDiscriminator
+
PolymorphicSerializer
works for me; when I build and run this snippet, it produces
Copy code
{
  "__type": "example.Bar"
}
EDIT: I thought this was running as expected when I wrote it, but it doesn't work for me anymore. I must have mixed it up with the
Container
example below.
do you have a simple example that doesn't work?
a
Hmm interesting
Actually, the same happens on classes, it’s not specific to interfaces
e
hmm. so indeed
PolymorphicSerializer
seems to not recognize the annotation,
@JsonClassDiscriminator
is only handled inside JSON.
I'm not sure if this is even resolvable without making ClassDiscriminator available to all formats, but it's worth filing a bug over, I think