Add JSON Serialize API to support ASP.NET polymorphic serialization
- Dominant language
- C#
- Stars
- 38.4k
- Forks
- 10.9k
- Avg merge
- 2d 6h
- Merged PRs (30d)
- 290
Description
## Background and Motivation
As described in https://github.com/dotnet/aspnetcore/issues/47548, ASP.NET has some internal logic around how it serializes objects to JSON for Minimal APIs and MVC. When fixing this issue in https://github.com/dotnet/aspnetcore/pull/47859, I noticed that this logic is spread out between:
* MVC's SystemTextJsonOutputFormatter
* HttpResultsHelper
* ExecuteHandlerHelper (shared between Http.Extensions and Routing)
* RequestDelegateGenerator generated code
The logic for all 4 looks like:
https://github.com/dotnet/aspnetcore/blob/6d30638626ff0f471f431ae2247ce95480e418ef/src/Shared/RouteHandlers/ExecuteHandlerHelper.cs#L39-L57
with the "ShouldUseWith" logic:
https://github.com/dotnet/aspnetcore/blob/6d30638626ff0f471f431ae2247ce95480e418ef/src/Shared/Json/JsonSerializerExtensions.cs#L13-L17
If users want to have this same serialization behavior, they would have to write that same logic in their app/library. Also, we need to encode this logic in the source generator, which means it isn't as serviceable because if we need to fix a bug in it, the dev needs to rebuild their app to get the fix.
We should come up with an API that we can shared code between these 4 places, and allow customers to serialize objects with the same behavior as how MVC and Minimal APIs does.
## Proposed API
TBD
## Usage Examples
TBD
## Alternative Designs
## Risks
The name of the API is a risk at confusing people what the difference between our existing APIs and this one do.
______
cc @halter73 @captainsafia @mitchdenny @eiriktsarpalis
Contributor guide
Assessment
This issue has not been assessed yet.