You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[JsonSerializer] Provide option to specify a custom default value for a type, property, or field #36236
#779 discusses options to ignore CLR default values during serialization (API approved).
Rather than using the CLR default, users may want to specify a custom default to be ignored. This issue is a placeholder for an API proposal to make this achievable.
When the prop is set to -1, which is the default value, the property is serialized when JsonIgnoreCondition.WhenWritingDefault is set. I would expect that property to not be serialized.
I believe that most of that functionality can now be achieved using a combination of the JsonPropertyInfo.ShouldSerialize/Get/Set delegates in the contract customization layer. There a limits to what values can be specified in the attribute layer, so I'd be inclined to close this in favor of the API surface exposed in #63686.
Activity
layomia commentedon Sep 1, 2020
From @steveoh in #41630
walterpg commentedon May 19, 2021
Raising the flag
FYI, I am considering returning to a tried-and-true third party to get this functionality. Custom
JsonConverters are not sustainable workarounds for my scenarios.eiriktsarpalis commentedon Oct 15, 2021
Might need to be considered in conjunction with this proposal: #55781 (comment)
eiriktsarpalis commentedon Oct 26, 2021
Also related #593 and #40395.
eiriktsarpalis commentedon Sep 2, 2022
I believe that most of that functionality can now be achieved using a combination of the
JsonPropertyInfo.ShouldSerialize/Get/Setdelegates in the contract customization layer. There a limits to what values can be specified in the attribute layer, so I'd be inclined to close this in favor of the API surface exposed in #63686.