Skip to content

Fix JsonIgnore behavior on init-only properties in source generation mode #112924

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
merged 6 commits into from
Jun 25, 2025

Conversation

ardabada
Copy link
Contributor

This change fixes #101877 where the [JsonIgnore] attribute applied to init-only properties is ignored in source generation mode. In the current behavior, the generated object initializer mistakenly invokes the init for properties marked with [JsonIgnore], which causes the value provided by the constructor to be overwritten (or set to null) during deserialization.

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

@dotnet-policy-service agree

@eiriktsarpalis eiriktsarpalis added the needs-author-action An issue or pull request that requires more info or actions from the author. label Jun 2, 2025
@eiriktsarpalis
Copy link
Member

/ba-g unrelated test failures

@eiriktsarpalis eiriktsarpalis merged commit 27c8fe0 into dotnet:main Jun 25, 2025
78 of 86 checks passed
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 attribute has no effect on init-only properties in source generation mode
2 participants