-
Notifications
You must be signed in to change notification settings - Fork 5.4k
JsonSerializerOptions copy constructor should include the metadata resolver #71716
Copy link
Copy link
Closed
Closed
Copy link
Labels
area-System.Text.Jsonbreaking-changeIssue or PR that represents a breaking API or functional change over a previous release.Issue or PR that represents a breaking API or functional change over a previous release.needs-breaking-change-doc-createdBreaking changes need an issue opened with https://github.com/dotnet/docs/issues/new?template=dotnetBreaking changes need an issue opened with https://github.com/dotnet/docs/issues/new?template=dotnet
Milestone
Metadata
Metadata
Assignees
Labels
area-System.Text.Jsonbreaking-changeIssue or PR that represents a breaking API or functional change over a previous release.Issue or PR that represents a breaking API or functional change over a previous release.needs-breaking-change-doc-createdBreaking changes need an issue opened with https://github.com/dotnet/docs/issues/new?template=dotnetBreaking changes need an issue opened with https://github.com/dotnet/docs/issues/new?template=dotnet
Type
Fields
Give feedbackNo fields configured for issues without a type.
With the release of source generation in .NET 6 the
JsonSerializerOptionscopy constructor was intentionally made to ignore itsJsonSerializerContextstate (see also dotnet/aspnetcore#38720). This made sense at the time sinceJsonSerializerContextwas designed to have a 1:1 relationship withJsonSerializerOptionsinstances.The implementation of #63686 generalizes
JsonSerializerContextwithIJsonTypeInfoResolver, which can be used to generate metadata for parametricJsonSerializerOptionsinstances. TheJsonSerializerContexttype and source generator have been retrofitted and now implementIJsonTypeInfoResolver.This issue proposes that we change the
JsonSerializerOptionscopy constructor so that it also incorporates the metadata resolver. This can potentially introduce a breaking change for users, for instance:For impacted users the suggested workaround is the following: