-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Closed
Labels
api-approvedAPI was approved in API review, it can be implementedAPI was approved in API review, it can be implementedarea-System.Text.Json
Milestone
Description
Background and motivation
Propose a public JsonSerializerOptions for the web, it could help avoid some duplicate cache
For example, if we extend the AsyncEnumerable for legacy frameworks, we could use the shared JsonSerializerOptions.Web without creating a new JsonSerializerOptions, and the original cache in runtime/aspnetcore etc would also benifit from this
new JsonSerializerOptions(JsonSerializerDefaults.Web) usage from grep:
https://grep.app/search?q=JsonSerializerOptions%28JsonSerializerDefaults.Web%29&filter[lang][0]=C%23
This may also help with the new analyzer rule
https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/ca1869
API Proposal
namespace System.Text.Json;
public sealed partial class JsonSerializerOptions
{
public static JsonSerializerOptions Default { get; }
+ public static JsonSerializerOptions Web { get; }
}API Usage
using var httpClient = new HttpClient();
httpClient.BaseAddress = new Uri("http://localhost:5297");
await using var responseStream = await httpClient.GetStreamAsync("api/Jobs");
// var stream = JsonSerializer.DeserializeAsyncEnumerable<Job>(responseStream, new JsonSerializerOptions(JsonSerializerDefaults.Web));
var stream = JsonSerializer.DeserializeAsyncEnumerable<Job>(responseStream, JsonSerializerOptions.Web);Alternative Designs
No response
Risks
No response
fowl2 and ktsin
Metadata
Metadata
Assignees
Labels
api-approvedAPI was approved in API review, it can be implementedAPI was approved in API review, it can be implementedarea-System.Text.Json