Skip to content

Conversation

@eiriktsarpalis
Copy link
Member

Updates the source generator so that generated code does not reference types of JsonIgnore'd properties unless the type is already present elsewhere in the type graph. Instead, it replaces the ignored property with a stub JsonPropertyInfo<object> instance which is necessary for certain runtime validations performed by the serializer. This prevents inadvertent referencing of types marked as experimental in the source generator.

Copy link
Contributor

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 updates the System.Text.Json source generator to avoid referencing types of JsonIgnore'd properties unless the type is already used elsewhere in the type graph. This prevents inadvertent referencing of types marked as experimental in the source generator.

  • Updates source generator logic to use stub JsonPropertyInfo<object> for ignored properties of unused types
  • Adds test infrastructure improvements with logging support
  • Includes new test cases for experimental types with JsonIgnore

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
System.Text.Json.SourceGeneration.Roslyn4.4.Unit.Tests.csproj Updates Roslyn API version from 4.4 to 4.8
JsonSourceGeneratorTests.cs Adds logging support and new test methods for experimental type scenarios
CompilationHelper.cs Adds logging infrastructure and diagnostic output capabilities
JsonSourceGenerator.Emitter.cs Core logic changes to avoid referencing types of ignored properties

@dotnet-policy-service
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.

Copy link
Member

@jeffhandley jeffhandley left a comment

Choose a reason for hiding this comment

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

Tests I suggest considering adding:

  1. A mixture of experimental and obsolete properties and fields on a type
  2. A type hierarchy that hits the case of naming collisions
  3. Scenarios that do not compile successfully, asserting where diagnostics are expected

@eiriktsarpalis eiriktsarpalis force-pushed the generator-skip-ignored-members branch from 357b2fc to 3ff1732 Compare October 8, 2025 19:13
Copy link
Member

@jeffhandley jeffhandley left a comment

Choose a reason for hiding this comment

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

Thanks for adding the extra tests. Looks great.

@eiriktsarpalis eiriktsarpalis merged commit 0986839 into dotnet:main Oct 9, 2025
86 checks passed
@jeffhandley
Copy link
Member

/backport to release/10.0

@github-actions
Copy link
Contributor

github-actions bot commented Oct 9, 2025

Started backporting to release/10.0: https://github.com/dotnet/runtime/actions/runs/18384128909

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants