-
-
Notifications
You must be signed in to change notification settings - Fork 56
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
Serialize type discriminator when using attributes too #138
Comments
Hi @MYDIH I try to put all that is not "documented api" to internal so that I can have less constraint linked to public api breaking changes. Could you explain why you're not using:
|
Hi and thank you for your time, Sorry that it wasn't clear enough, Actually I want to serialize polymorphic JSON with a "type" attribute containing the type. I don't want to have to specify this type in the code, it should be set automatically when a class is of a given type based on the mappings I use with KnownSubType. I would prefer that this field isn't taking part of the class even though it wouldn't be blocking if it wasn't possible. My other requirement is that I want to be able to achieve that using Attributes of my classes/fields for the reason I mentioned before. So far, when I'm using the documented method (the one you describe), the type isn't serialized along with the class. If I want to serialize it, it seems I have two options from my understanding, use the method where I need to generate a I tried adding the type field to my classes, but it is not automatically filled with the proper type when serializing. It seems I need to specify it manually. Tell me if I'm wrong of course. What I did in the fork is creating a new constructor for the class I hope it makes everything clear enough ... |
+1, this functional is very necessary |
1 similar comment
+1, this functional is very necessary |
@manuc66 Any chance a PR will be approved if we change the ctor to become public like MYDIH suggests? |
+1 |
…ator Propose an implementation for #138
Hi,
I'm using polymorphic deserialization in the context of generated data classes. The fact that everything is configured through Attributes is really helping in this case because it means the models are self sufficient, they don't need a companion class that allow well configured deserialization. I don't want to have to set the type by hand or anything, but I still need to serialize deserializable JSON though (with the discriminator property serialized) ...
I forked this projet and found that adding the
JsonSubtypesByDiscriminatorValueConverter
like so achieves what I want :(I basically changed the visibility of the constructor in the fork)
I didn't know at the time the reason for this limitation, but from my experience (2 years of production code), I never experienced any problems with it.
Now I'm years later, and I need to use the fallback type attribute (what a relief that this thing exists). The Attribute isn't working with the above method, though creating a new constructor will achieve what I want.
Describe the solution you'd like
Is there a reason for this class to be strictly internal even though you can get a neat feature using it directly ?
Would you consider exposing it correctly (I mean in a "compliant with the API vision" way) ?
With the correct directions, I could file a PR
Describe alternatives you've considered
I would keep my fork ...
The text was updated successfully, but these errors were encountered: