-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
JsonSerializerOptions copy constructor should include the metadata resolver #71716
Comments
Tagging subscribers to this area: @dotnet/area-system-text-json, @gregsdennis Issue DetailsWith the release of source generation in .NET 6 the The implementation of #63686 generalizes This issue proposes that we change the
For impacted users the suggested workaround is the following: var options = new JsonSerializerOptions(MyContext.Default.Options);
options.TypeInfoResolver = null; // unset the `MyContext.Default` as the resolver for the options instance.
|
Tagging subscribers to this area: @dotnet/area-system-text-json, @gregsdennis Issue DetailsWith the release of source generation in .NET 6 the The implementation of #63686 generalizes This issue proposes that we change the
For impacted users the suggested workaround is the following: var options = new JsonSerializerOptions(MyContext.Default.Options);
options.TypeInfoResolver = null; // unset the `MyContext.Default` as the resolver for the options instance.
|
…t#71714 Include JsonSerializerContext in JsonSerializerOptions copy constructor. Fix dotnet#71716 Move reflection-based converter resolution out of JsonSerializerOptions. Fix dotnet#68878
* Remove implicit fallback to reflection-based serialization. Fix #71714 Include JsonSerializerContext in JsonSerializerOptions copy constructor. Fix #71716 Move reflection-based converter resolution out of JsonSerializerOptions. Fix #68878 * Address feedback & add one more test * Update src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializerContext.cs Co-authored-by: Stephen Toub <[email protected]> * fix build * Bring back throwing behavior in JsonSerializerContext and add tests * Only create caching contexts if a resolver is populated * Add null test for JsonSerializerContext interface implementation. * skip RemoteExecutor test in netfx targets * Add DefaultJsonTypeInfoResolver test for types with JsonConverterAttribute * remove nullability annotation * Update src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializerOptions.Converters.cs Co-authored-by: Krzysztof Wicher <[email protected]> Co-authored-by: Stephen Toub <[email protected]> Co-authored-by: Krzysztof Wicher <[email protected]>
With the release of source generation in .NET 6 the
JsonSerializerOptions
copy constructor was intentionally made to ignore itsJsonSerializerContext
state (see also dotnet/aspnetcore#38720). This made sense at the time sinceJsonSerializerContext
was designed to have a 1:1 relationship withJsonSerializerOptions
instances.The implementation of #63686 generalizes
JsonSerializerContext
withIJsonTypeInfoResolver
, which can be used to generate metadata for parametricJsonSerializerOptions
instances. TheJsonSerializerContext
type and source generator have been retrofitted and now implementIJsonTypeInfoResolver
.This issue proposes that we change the
JsonSerializerOptions
copy 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:
The text was updated successfully, but these errors were encountered: