-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Request: System.Text.Json Serialization with Opt-In #30180
Comments
From @cedemax in https://github.com/dotnet/corefx/issues/41633
|
This can be achieved using DataContractAttribute and DataMemberAttribute, if we provide support for them: https://github.com/dotnet/corefx/issues/38758. We should be careful not to provide too many ways to do the same thing. |
@layomia is this still in the works for 5.0? A library I depend on uses Newtonsoft.Json because S.T.J is missing this and so then my project pulls in S.T.J for what it does itself, and then that also depends on Discord.Net (which is the library that uses Newtonsoft.Json for this opt-in stuff as a class level attribute itself). It just would be nice to finally be able for someone like me to just pr that library with the updated S.T.J that has this feature so that way it can drop Newtonsoft and my pain would be gone. |
Duplicate of #593 |
@eiriktsarpalis Mine was posted on July, the duplicate was posted in December. So the others has duplicated mine actually. |
Sure, keep in mind this is all about keeping our backlog tidy not giving credit to the earliest feature request. The other issue happens to contain more recent activity and links to related issue we are planning, which is the only reason why I closed this one. I would recommend continuing to contribute to the other issue (either via upvoting or commenting on the design discussion). |
It's all about which one will take less work to provide details from both - the other one seem to have more activity and details. What I'm curious is how the other issue has lower number even though yours was created earlier... |
I think the explanation is here:
The other issue seems to have been already created in dotnet/runtime, it was never moved. |
Similar to https://www.newtonsoft.com/json/help/html/JsonObjectAttributeOptIn.htm an option to serialize only specific properties would be very useful. Especially if the amount of properties to include are less than the properties to exclude.
For example I have one base class
Animal
where lots of animal type classes inherits from:Cat, Dog, Horse, Monkey, ...
(and imagine https://github.com/dotnet/corefx/issues/39031 gets addressed sometime). It's easier to just include the property by a custom attribute rather to exclude all unwanted for maintainability reasons. For the same reasons I also don't want to mess around with a sort of converter or something when there are many classes.In Newtonsoft Json it was easy and worked very well by just adding a custom attribute on top of the class and skip >300 JsonIgnore attributes on every property.
The text was updated successfully, but these errors were encountered: