Skip to content

Proposal to fix issue #38800 System.Text.Json: IgnoreNullValues ignores field that have default value - #38811

Closed
molinch wants to merge 4 commits into
dotnet:masterfrom
molinch:master
Closed

molinch wants to merge 4 commits into
dotnet:masterfrom
molinch:master

Conversation

@molinch

@molinch molinch commented Jul 6, 2020 •

Copy link
Copy Markdown

Fixes #38800

@Dotnet-GitSync-Bot

Copy link
Copy Markdown
Collaborator

Note regarding the new-api-needs-documentation label:

This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, to please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change.

@Dotnet-GitSync-Bot

Copy link
Copy Markdown
Collaborator

I couldn't figure out the best area label to add to this PR. If you have write-permissions please help me learn by adding exactly one area label.

@dnfadmin

dnfadmin commented Jul 6, 2020 •

Copy link
Copy Markdown

CLA assistant check
All CLA requirements met.

@molinch

molinch commented Jul 6, 2020

Copy link
Copy Markdown
Author

@layomia sorry it took me a few commits to fix the tests, it was really hard for me to run them
let me know your thoughts, thanks !

@layomia layomia added this to the 5.0.0 milestone Jul 12, 2020
@layomia

layomia commented Jul 12, 2020

Copy link
Copy Markdown
Contributor

Thanks for your contribution, @molinch.

This change requires API review and approval. Please see the process here.

Fixing the regression where value type properties are ignored when serializing with IgnoreNullValues active does not need any API changes. I've opened a PR to fix this here - #38800.

FWIW - the way to prevent individual value type properties from being ignored when JsonIgnoreCondition.WhenWritingDefault is active on JsonSerializerOptions is to set [JsonIgnore(Condition = JsonIgnoreCondition.Never)] on the properties you wish to exclude.

If you have another concern or API suggestion, please open another issue, taking into account the documentation linked above.

@layomia layomia closed this Jul 12, 2020
@molinch

molinch commented Jul 12, 2020 •

Copy link
Copy Markdown
Author

Hi @layomia, thanks for fixing the issue. While I know about JsonIgnoreCondition.Never I don't think that having to set it on top of every value type makes sense, hence I proposed the API suggestion #39152
Thanks!

@ghost ghost locked as resolved and limited conversation to collaborators Dec 8, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

System.Text.Json: IgnoreNullValues ignores field that have a default value

4 participants