-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
2 changed files
with
41 additions
and
0 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
src/OrchardCore/OrchardCore.Abstractions/Json/JsonOptionsConfigurations.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using System.Text.Json; | ||
using Microsoft.AspNetCore.Http.Json; | ||
using Microsoft.Extensions.Options; | ||
|
||
namespace OrchardCore.Json; | ||
|
||
public class JsonOptionsConfigurations : IConfigureOptions<JsonOptions> | ||
{ | ||
private readonly JsonSerializerOptions _jsonSerializerOptions; | ||
|
||
public JsonOptionsConfigurations(IOptions<JsonSerializerOptions> jsonSerializerOptions) | ||
{ | ||
_jsonSerializerOptions = jsonSerializerOptions.Value; | ||
} | ||
|
||
public void Configure(JsonOptions options) | ||
{ | ||
options.SerializerOptions.DefaultIgnoreCondition = _jsonSerializerOptions.DefaultIgnoreCondition; | ||
options.SerializerOptions.ReferenceHandler = _jsonSerializerOptions.ReferenceHandler; | ||
options.SerializerOptions.ReadCommentHandling = _jsonSerializerOptions.ReadCommentHandling; | ||
options.SerializerOptions.PropertyNameCaseInsensitive = _jsonSerializerOptions.PropertyNameCaseInsensitive; | ||
options.SerializerOptions.AllowTrailingCommas = _jsonSerializerOptions.AllowTrailingCommas; | ||
options.SerializerOptions.WriteIndented = _jsonSerializerOptions.WriteIndented; | ||
options.SerializerOptions.PropertyNamingPolicy = _jsonSerializerOptions.PropertyNamingPolicy; | ||
options.SerializerOptions.Encoder = _jsonSerializerOptions.Encoder; | ||
options.SerializerOptions.TypeInfoResolver = _jsonSerializerOptions.TypeInfoResolver; | ||
|
||
foreach (var resolver in _jsonSerializerOptions.TypeInfoResolverChain) | ||
{ | ||
options.SerializerOptions.TypeInfoResolverChain.Add(resolver); | ||
} | ||
|
||
foreach (var converter in _jsonSerializerOptions.Converters) | ||
{ | ||
options.SerializerOptions.Converters.Add(converter); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters