-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Allow JsonIgnore on classes and structs #54269
Comments
Tagging subscribers to this area: @eiriktsarpalis, @layomia Issue DetailsBackground and MotivationToday, For example, today one must write:
When it would be much nicer to be able to write:
Proposed API
Usage ExamplesSee Above. Alternative DesignsToday you can specify a global RisksNone. Today
|
Related to #50294 and #55781. In #55781 (comment) I sketched a potential API for customizing ignored values (and not just |
Closing in favor of #55781 (comment) |
Background and Motivation
Today,
JsonIgnore
can only be specified on properties and fields. This creates a needlessly redundant scenario whenJsonIgnore
should be applied to all members of a type.For example, today one must write:
When it would be much nicer to be able to write:
Proposed API
[JsonIgnore(Condition = ...)]
should be specifiable on a class/struct to indicate that all properties/fields of that type have the specified defaultJsonIgnore
condition.Usage Examples
See Above.
Alternative Designs
Today you can specify a global
JsonIgnore
value usingJsonSerializerOptions.DefaultIgnoreCondition
however, this is undesirable because it will impact other types you are (de)serializing and not just your target type.Risks
None. Today
JsonIgnore
cannot be applied to classes so enabling it will not be a breaking change.The text was updated successfully, but these errors were encountered: