-
Notifications
You must be signed in to change notification settings - Fork 626
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ClassDiscriminatorMode annotation for data classes #2883
Comments
Why you need annotation exactly and why the general |
The use-case here is that we define message types consumed by multiple parties who should be able to create and serialize messages. These created messages (JSONs) will be processed by us again, for which we need to deserialize them and rely on the type field. We provide functions to serialize and deserialize them correctly (using the polymorphic type) for them to use, but it is easy for the third-parties to mess up here if they do it themselves:
Having an annotation directly on the data class to indicate to always include the type field would decrease the risk of some party not including the type field massively. Is there a workaround to achieve something similar? I would suspect that one could include the serialName directly into the data class, but not sure if that would play nicely with the library. |
Hm, I see. So |
Exactly. We provide methods on the Base class to do the serialization correctly i.e. |
No, we don't have this. The only way is to provide pre-configured Json instance in your library or convertor |
Hi there,
similarly to JsonClassDiscriminator, I would like an annotation type to indicate the discriminator mode for data classes:
The motivation is that we have a polymorphic data class consumed by third-party actors but we want to ensure that the serialized classes always include the class type annotation, regardless of whether the third-party actors serialize it using the concrete or the polymorphic type.
If there is a work-around already known, please feel free to share.
The text was updated successfully, but these errors were encountered: