andrew

    andrew

    8 months ago
    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?
    This:
    [{ "name": "Unit 101", "unlock_technology": "august", }, { "name": "Unit 102", "unlock_technology": "august" }, { "name": "Gym", "unlock_technology": "brivo_ble" }]
    Would equate to:
    [ AugustLock(name = "Unit 101"), AugustLock(name = "Unit 102"), BrivoLock(name = "Gym") ]
    Where
    classDiscriminator
    is
    unlock_technology
    Dominaezzz

    Dominaezzz

    8 months ago
    Use SerialName on AugustLock
    andrew

    andrew

    8 months ago
    Are we able to set class discriminator per class being serialized?
    Dominaezzz

    Dominaezzz

    8 months ago
    Yes, you can give each class a serial name.
    Unless you mean the discriminator field name. That can also be set per base class.
    andrew

    andrew

    8 months ago
    yes, the discriminator field name
    How would that be done?
    Dominaezzz

    Dominaezzz

    8 months ago
    JsonClassDiscriminator annotation
    andrew

    andrew

    8 months ago
    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
    Dominaezzz

    Dominaezzz

    8 months ago
    What you have looks mostly right.
    Only issue is that you can't use the discriminator as a field in the class.
    Nikky

    Nikky

    8 months ago
    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