Skip to content
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

add new JsonIgnoreAttribute WhenWriting/WhenReading #104562

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

WeihanLi
Copy link
Contributor

@WeihanLi WeihanLi commented Jul 8, 2024

feat: add new JsonIgnoreAttribute WhenWriting/WhenReading

fixes #66490

  • test cases

Copy link

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, 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.

1 similar comment
Copy link

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, 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.

/// <summary>
/// Property is ignored during deserialization
/// </summary>
WhenReading = 5,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eiriktsarpalis, how does someone specify multiple of these? e.g. if I have a property that I want to be ignored when reading and when writing null, how do I achieve that? Or is that not a scenario that matters?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not possible, which shows the limits of the JsonIgnoreCondition design. These enums eventually map to the JsonPropertyInfo.ShouldSerialize and JsonPropertyInfo.Set delegates, so a user wanting to introduce their own ignore conditions can configure these via the contract customization APIs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-System.Text.Json community-contribution Indicates that the PR has been added by a community member new-api-needs-documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[API Proposal]: Extend JsonIgnoreCondition
3 participants