Thread
#serialization
    Eugen Martynov

    Eugen Martynov

    8 months ago
    Is there way to overrider json key that is responsible for the sealed class serialisation pick up?
    I wrote
    JsonContentPolymorphicSerializer
    it works great for deserialisation however, it doesn't write field during serialisation
    Eugen Martynov

    Eugen Martynov

    8 months ago
    Yeah, I know it. So the only way it is to write completely new serialiser in this case
    What if I try to override descriptor? Or descriptor is only used to pickup correct serialiser and is not used during serialisation?
    Paul Woitaschek

    Paul Woitaschek

    8 months ago
    One Idea I have is to maybe utilize the JsonTransformingSerializer and rewrite the type field
    Might be worth a shot
    Eugen Martynov

    Eugen Martynov

    8 months ago
    Super thank you!
    It looks like really a hack. I probably will just write a staightforward serialiser and talk to BE people to ask use type for such cases
    Paul Woitaschek

    Paul Woitaschek

    8 months ago
    Seems to be some kind of a standard
    Eugen Martynov

    Eugen Martynov

    8 months ago
    Thank you!
    Paul Woitaschek

    Paul Woitaschek

    8 months ago
    @Eugen Martynov Look what I found in a PR I was reviewing 😛 https://github.com/Kotlin/kotlinx.serialization/blob/master/docs/json.md#class-discriminator
    Eugen Martynov

    Eugen Martynov

    8 months ago
    🙂 Great!!! I still need ask for the consistency from backend people. Otherwise I have to find a way how to tweak Json for every specific case. Here is also interesting decision - it is rather connected to the deserialization and not class itself.
    Paul Woitaschek

    Paul Woitaschek

    8 months ago
    Yeah I’d make a very strong case for sticking to the convention
    Eugen Martynov

    Eugen Martynov

    8 months ago
    There is the way!
    @JsonClassDiscriminator
    Paul Woitaschek

    Paul Woitaschek

    8 months ago
    That one is well hidden 😃
    Eugen Martynov

    Eugen Martynov

    8 months ago
    And if you have consistency in your BE you can do it with
    Json {
       classDiscriminator = "out_type"
    }