Allow Custom JsonSerializerOptions for Minimal Actions
- Dominant language
- C#
- Stars
- 38.4k
- Forks
- 10.9k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 281
Description
## Background and Motivation
Add ability to have custom `JsonSerializerOptions` for serializing and deserializing in minimal actions.
## Proposed API
```diff
namespace Microsoft.AspNetCore.Builder
{
public static class DelegateEndpointRouteBuilderExtensions
{
+ public static DelegateEndpointConventionBuilder Map(
+ this IEndpointRouteBuilder endpoints,
+ RoutePattern pattern,
+ Delegate handler,
+ JsonSerializerOptions options)
}
}
namespace Microsoft.AspNetCore.Http
{
public sealed class RequestDelegateFactoryOptions
{
+ public JsonSerializerOptions JsonSerializerOptions { get; init; }
}
}
```
## Usage Examples
``` C#
var jsonOptions = new JsonSerializerOptions
{
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
};
app.Map("\action", () => MyAction(), jsonOptions);
```
## 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.
```diff
public static class DelegateEndpointRouteBuilderExtensions
{
+ public static DelegateEndpointConventionBuilder WithJsonOptions(
+ this DelegateEndpointConventionBuilder builder,
+ JsonSerializerOptions options)
}
```
## Risks
Contributor guide
Assessment
This issue has not been assessed yet.