-
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
Obsolete JsonSerializerOptions.AddContext #83280
Comments
Tagging subscribers to this area: @dotnet/area-system-text-json, @gregsdennis Issue DetailsBackground & MotivationThe We should obsolete
API Proposalpublic class JsonSerializerOptions
{
[Obsolete(/* SYLIB code TBD? */)]
public void AddContext<TContext>() : where TContext : JsonSerializerContext
}
|
Looks good as proposed. Confirm with @terrajobst that System.Text.Json should use SYSLIB codes. |
- Removes all usages of JsonSerializerOptions.AddContext, which will be obsoleted by dotnet/runtime#83280 - Update ProblemDetailsJsonContext to be added just before the DefaultJsonTypeInfoResolver if it is the last resolver in the chain. Otherwise, add it to the end of a non-empty resolver chain. - Small clean up in the API template's usings
* Use Json TypeInfoResolverChain - Removes all usages of JsonSerializerOptions.AddContext, which will be obsoleted by dotnet/runtime#83280 - Update ProblemDetailsJsonContext to be added in a Configure<JsonOptions>() call back and to always be added to the beginning of the resolver chain at that time - This gives us the simplest, most understandable pattern for all libraries to follow. - Small clean up in the API template's usings * Change ProblemDetailsJsonOptionsSetup to use Configure instead of PostConfigure. When adding the ProblemDetailsJsonContext, we always prepend it to the beginning of the chain at the time the configure step is executed, no matter the state of the chain. This allows for a simpler, more understandable policy for all libraries that want to add their JsonContext into the JsonSerializerOptions resolver chain. The order of the chain is now determined by the order that the configure steps were registered in DI (for example when AddProblemDetails() was called).
Background & Motivation
The
JsonSerializerOptions.AddContext<TContext>()
method was introduced in .NET 6 as a means to associateJsonSerializerOptions
instances with a givenJsonSerializerContext
type. This method was largely superseded in .NET 7 with the introduction of contract customization and theJsonSerializerOptions.TypeInfoResolver
property.We should obsolete
AddContext
for the following reasons:JsonSerializerOptions.TypeInfoResolverChain
when manipulating resolver chains.JsonSerializerContext
type parameters, not with arbitraryIJsonTypeInfoResolver
instances.JsonSerializerOptions
for further modification:API Proposal
cc @eerhardt
The text was updated successfully, but these errors were encountered: