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

Open
wants to merge 6 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.

@WeihanLi WeihanLi force-pushed the extended-json-ignore-condition branch from 4ac298c to c92014b Compare July 22, 2024 17:56
@WeihanLi WeihanLi force-pushed the extended-json-ignore-condition branch from c92014b to 80b411a Compare July 25, 2024 16:19
@WeihanLi WeihanLi force-pushed the extended-json-ignore-condition branch from 9b27aba to 58a0eb7 Compare July 31, 2024 16:54
@WeihanLi WeihanLi marked this pull request as ready for review July 31, 2024 23:00
@WeihanLi WeihanLi force-pushed the extended-json-ignore-condition branch from 58a0eb7 to 5ec8c18 Compare July 31, 2024 23:00
@eiriktsarpalis
Copy link
Member

@WeihanLi thanks for submitting the PR, however since we're currently in the process of finishing up .NET 9 we are no longer merging PRs adding new features. We can revisit this in a couple weeks' time once the .NET 9 branch has been snapped from main.

@eiriktsarpalis eiriktsarpalis added this to the 10.0.0 milestone Aug 2, 2024
@eiriktsarpalis eiriktsarpalis added the NO-MERGE The PR is not ready for merge yet (see discussion for detailed reasons) label Aug 2, 2024
@eiriktsarpalis eiriktsarpalis removed the NO-MERGE The PR is not ready for merge yet (see discussion for detailed reasons) label Sep 11, 2024
@eiriktsarpalis
Copy link
Member

Apologies for the delay getting back to you, we can continue work on this PR for .NET 10 now.

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