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

Implement the JsonSerializer.IsReflectionEnabledByDefault feature switch #83844

Merged

Conversation

eiriktsarpalis
Copy link
Member

@eiriktsarpalis eiriktsarpalis commented Mar 23, 2023

Fix #83279.

@ghost
Copy link

ghost commented Mar 23, 2023

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

Issue Details

Fix #83279.

Note that this scales back the scope of the API as approved, since populating a resolver at the default constructor creates usability issues when used in conjunction with TypeInfoResolverChain collection initializers:

var options = new JsonSerializerOptions { TypeInfoResolverChain = { MyContextA.Default, MyContextB.Default } };
Assert.Equal(new [] { DefaultJsonTypeInfoResolver, MyContextA.Default, MyContextB.Default }, options.TypeInfoResolverChain);

Instead, this PR simply wires the feature switch to the JsonSerializer methods, disabling the delayed TypeInfoResolver population logic.

Author: eiriktsarpalis
Assignees: eiriktsarpalis
Labels:

area-System.Text.Json

Milestone: -

@eiriktsarpalis eiriktsarpalis added this to the 8.0.0 milestone Mar 23, 2023
Copy link
Member

@krwq krwq left a comment

Choose a reason for hiding this comment

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

LGTM

@eiriktsarpalis eiriktsarpalis changed the title Implement the STJ.DisableDefaultReflection feature switch Implement the STJ.UseReflectionDefault feature switch Mar 27, 2023
@eiriktsarpalis eiriktsarpalis changed the title Implement the STJ.UseReflectionDefault feature switch Implement the JsonSerializer.IsReflectionEnabledByDefault feature switch Apr 3, 2023
@eiriktsarpalis eiriktsarpalis added the NO-MERGE The PR is not ready for merge yet (see discussion for detailed reasons) label Apr 3, 2023
@eiriktsarpalis
Copy link
Member Author

Holding off from merging until the revised API has been approved.

@eiriktsarpalis eiriktsarpalis removed the NO-MERGE The PR is not ready for merge yet (see discussion for detailed reasons) label Apr 4, 2023
eiriktsarpalis and others added 4 commits April 5, 2023 15:35
…ion/JsonSerializer.Helpers.cs

Co-authored-by: Eric Erhardt <eric.erhardt@microsoft.com>
…immingTests/IsReflectionEnabledByDefaultFalse.cs

Co-authored-by: Eric Erhardt <eric.erhardt@microsoft.com>
Copy link
Member

@eerhardt eerhardt left a comment

Choose a reason for hiding this comment

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

Nice work, @eiriktsarpalis.

LGTM

@eiriktsarpalis eiriktsarpalis merged commit 0f11212 into dotnet:main Apr 5, 2023
@eiriktsarpalis eiriktsarpalis deleted the feature/json-reflection-flag branch April 5, 2023 20:21
eerhardt added a commit to dotnet/sdk that referenced this pull request Apr 14, 2023
Adds a msbuild property that ties to the feature switch implemented in dotnet/runtime#83844.

Default JsonSerializerIsReflectionEnabledByDefault in ASP.NET PublishAot apps to start the replacement of the ASP.NET JSON feature switch.

Co-authored-by: Eric Erhardt <eric.erhardt@microsoft.com>
@ghost ghost locked as resolved and limited conversation to collaborators May 6, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add an AppContext switch that disables using reflection by default in JsonSerializerOptions
8 participants