Is there any way to utilize <classDiscriminator> o...
# serialization
a
Is there any way to utilize classDiscriminator on a specific key when deserializing an abstract class, but without using the qualified name as a value, but a custom value?
d
Use SerialName on AugustLock
a
Are we able to set class discriminator per class being serialized?
d
Yes, you can give each class a serial name.
Unless you mean the discriminator field name. That can also be set per base class.
a
yes, the discriminator field name
How would that be done?
d
JsonClassDiscriminator annotation
a
Ah, was looking at the wrong source for the annotation, thanks man!
Also
Do they expect you to match the field name or the serial name?
It's gonna be a while before I can test this, migrating to a brand new type
Looks like it's lining up with whatever serial name would be
d
What you have looks mostly right.
Only issue is that you can't use the discriminator as a field in the class.
n
i mark such fields as
@Transient
and then add the
@SerialiName
to the subclasses of the sealed/abstract class that generally works i wish there was a way to teach serialization how to infer the type from a custom field and have that in the class too.. but that.. is complication and could lead to inconsistency