-
Notifications
You must be signed in to change notification settings - Fork 10.2k
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
Allow Custom JsonSerializerOptions for Minimal Actions #35904
Comments
No I don’t think we should do this. The options are:
|
I thought there were no static global options for System.Text.Json.
Fair enough. The only thing left is for serializing from body which I guess @davidfowl I have nothing more to add, the issue could be closed. 🙂 |
We should add a first class API to configure the JsonOptions. This isn't global for all calls, it's for calls to ReadAsJsonAsync and WriteAsJsonAsync |
Ah I see what you're talking about. aspnetcore/src/Http/Http.Extensions/src/HttpRequestJsonExtensions.cs Lines 189 to 193 in 8b30d86
So should I update the proposal to this one? public static class ServiceCollectionExtensions
{
/// <summary>
/// Configures JsonOptions for WriteAsJsonAsync and ReadFromJsonAsync.
/// </summary>
public static IServiceCollection ConfigureJsonOptions(this IServiceCollection services, Action<Microsoft.AspNetCore.Http.Json.JsonOptions> action)
{
return services.Configure(action);
}
} |
We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process. |
Thanks for contacting us. We're moving this issue to the |
@Kahbazi and @davidfowl We also have a namespace issue that we may need to address if we were to provide a first-class API to globally configure JsonSerializerOptions. Notice that the following @davidfowl Given the namespace issue, do we need to provide a first-class API to hide the code below and help avoid confusion? builder.Services.Configure<Microsoft.AspNetCore.Mvc.JsonOptions>(opts =>
{
//opts.JsonSerializerOptions.PropertyNamingPolicy = null;
//More Configs if needed.
}); |
Thanks for contacting us. We're moving this issue to the |
If we can't use a specific JsonSerializerOptions per endpoint, how can we make sure the openAPI schema is generated correctly? Even now (didn't look at dotnet 9) we have to synchronize both Microsoft.AspNetCore.Http.Json.JsonOptions and Microsoft.AspNetCore.Mvc.JsonOptions to make sure the OpenAPI schema generated by SwaggerGen is accurate. Beeing able to specify the JsonSerializerOptions on an endpoint or a group of endpoints could bring so much flexibility. If the answer is still Results.Json, could we then have the ability to provide the JsonSerializerOptions in the Produces and Acccepts? |
This could be really useful in certain scenarios. I came across this because I need to deserialize a client request using a custom JsonConverter, and I would prefer not to add it globally but rather use it only for that specific endpoint. |
Background and Motivation
Add ability to have custom
JsonSerializerOptions
for serializing and deserializing in minimal actions.Proposed API
Usage Examples
Alternative Designs
This could also be added via Endpoint metadata in order to prevent all extra overloads (MapGet, MapPost, ...), but the downside is that it would add an extra fetch from
Endpoint.Metadata
for serializing and deserializing.Risks
The text was updated successfully, but these errors were encountered: