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
System.Text.Json: IgnoreNullValues ignores field that have a default value #38800
.NET SDK: 5.0.100-preview.6.20318.15
Windows 10 or Linux image mcr.microsoft.com/dotnet/aspnet:5.0-buster-slim show the same behaviour
Architecture: x64, but doesn't seem specific to it
Regression?
It is a regression in .NET Core 3.1 it was working as expected.
It was also fine in former .NET 5 versions.
Other information
I would be happy to help adding the test case to the framework tests if guided.
See how it added that with Options.IgnoreNullValues we ignore the default values on read/write.
While that is correct for reference types, it's not the case for value types.
From that commit I see that IgnoreNullValues has been obsoleted, replaced by DefaultIgnoreCondition.
Still I believe that:
existing code should still work as it used to
we still need to differentiate serialization of null from default value, these have very different semantic in Javascript (which is the target of that serializer)
From the mentioned commit:
I think that WhenNull should be kept as an option, which would have the same effect as obsolete Options.IgnoreNullValues.
Most likely most folks will want that behaviour.
changed the title [-]System.Text.Json: IgnoreNullValues ignores field that are zero[/-][+]System.Text.Json: IgnoreNullValues ignores field that have a default value[/+]on Jul 6, 2020
Activity
molinch commentedon Jul 6, 2020
This commit might be the root cause: c2291eb#diff-6945dba66187c255555ac8232ef4584dR140
See how it added that with Options.IgnoreNullValues we ignore the default values on read/write.
While that is correct for reference types, it's not the case for value types.
From that commit I see that IgnoreNullValues has been obsoleted, replaced by DefaultIgnoreCondition.
Still I believe that:
From the mentioned commit:

I think that WhenNull should be kept as an option, which would have the same effect as obsolete Options.IgnoreNullValues.
Most likely most folks will want that behaviour.
Proposal to fix issue dotnet#38800 System.Text.Json: IgnoreNullValues…
[-]System.Text.Json: IgnoreNullValues ignores field that are zero[/-][+]System.Text.Json: IgnoreNullValues ignores field that have a default value[/+]