-
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 should provide explicit control over chained IJsonTypeInfoResolvers #83095
Comments
Tagging subscribers to this area: @dotnet/area-system-text-json, @gregsdennis Issue DetailsBackground and motivationWhen shipped in .NET 7, the contract customization feature added support for chaining resolvers by means of the var options = new JsonTypeInfoResolver
{
TypeInfoResolver = JsonTypeInfoResolver.Combine(ContextA.Default, ContextB.Default, ContextC.Default);
}; Based on feedback we've received, this approach has a couple of usability issues:
API Proposalnamespace System.Text.Json;
public partial class JsonSerializerOptions
{
public IJsonTypeInfoResolver? TypeInfoResolver { get; set; }
+ public IList<IJsonTypeInfoResolver> ChainedTypeInfoResolvers { get; set; }
} With this API added, we should also revert the recent change to API UsageThe new property should complement and be mutually consistent with the existing Setting a resolver to
|
Author: | eiriktsarpalis |
---|---|
Assignees: | - |
Labels: |
|
Milestone: | 8.0.0 |
namespace System.Text.Json;
public partial class JsonSerializerOptions
{
public IList<IJsonTypeInfoResolver> TypeInfoResolverChain { get; }
} |
Background and motivation
When shipped in .NET 7, the contract customization feature added support for chaining resolvers by means of the
JsonTypeInfoResolver.Combine
method:Based on feedback we've received, this approach has a couple of usability issues:
IJsonTypeInfoResolver
implementation, there is no way for users to introspect the chain or remove components from it.API Proposal
namespace System.Text.Json; public partial class JsonSerializerOptions { public IJsonTypeInfoResolver? TypeInfoResolver { get; set; } + public IList<IJsonTypeInfoResolver> TypeInfoResolverChain { get; } }
With this API added, we should also revert the recent change to
AddContext
in #80698 since it provided an inadequate attempt to address the same underlying issue:AddContext
method in .NET 7.API Usage
The new property should complement and be mutually consistent with the existing
TypeInfoResolver
property. Here are a few examples:Setting a resolver to
TypeInfoResolver
Setting a combined resolver to
TypeInfoResolver
Appending a resolver to
ChainedTypeInfoResolvers
Prepending a resolver to
ChainedTypeInfoResolvers
:cc @brunolins16 @davidfowl @eerhardt
The text was updated successfully, but these errors were encountered: