Skip to content

fix json source generator serialize when writing #116004

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

Merged

Conversation

WeihanLi
Copy link
Contributor

fixes #116003

@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label May 27, 2025
Copy link
Contributor

Tagging subscribers to this area: @dotnet/area-system-text-json, @gregsdennis
See info in area-owners.md if you want to be subscribed.

@WeihanLi WeihanLi marked this pull request as ready for review May 27, 2025 04:55
@Copilot Copilot AI review requested due to automatic review settings May 27, 2025 04:55
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes serialization behavior in the source generator so that properties marked with JsonIgnoreCondition.WhenWriting are correctly omitted, and adds corresponding tests.

  • Added SerializedValueCheckType.Ignore enum value and mapping for WhenWriting
  • Updated emitter to handle the new ignore case in fast-path code
  • Introduced two tests (SerializeIgnoreWhenWritingTest and SerializeIgnoreWhenReadingTest) and the IgnoreWhenReadingWritingPerson type

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
JsonSerializerContextTests.cs Added new tests and the IgnoreWhenReadingWritingPerson type
JsonSourceGenerator.Emitter.cs Introduced Ignore enum case, mapped WhenWriting, and stubbed fast-path logic for skipping properties

Copy link
Member

@eiriktsarpalis eiriktsarpalis left a comment

Choose a reason for hiding this comment

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

Thanks

@eiriktsarpalis eiriktsarpalis merged commit 4cb08fc into dotnet:main May 27, 2025
83 of 86 checks passed
@WeihanLi WeihanLi deleted the fix-json-generator-ignore-when-writing branch May 28, 2025 02:32
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

JsonIgnore not working properly for generator
3 participants