dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
35.5k stars 10.04k forks source link

Add JSON Serialize API to support ASP.NET polymorphic serialization #47973

Open eerhardt opened 1 year ago

eerhardt commented 1 year ago

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:

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

mitchdenny commented 1 year ago

Interesting comment about serviceability. If someone happens to be using RDG without native AOT I guess they could run into that issue. but in the case of RDG with native AOT the serviceability problem is inevitable.

shivangnayar-dev commented 1 year ago

can i be assigned this issue

captainsafia commented 1 year ago

@shivangnayar-dev At the moment, the issue isn't ready for implementation. The next step is to polish up the requirements here into an API proposal (fill in all the TBD sections) and take it through API review. You're welcome to help with that process but it would be helpful to have context into the background here...

I'd recommend checking out the help-wanted label for issues that are more shovel-ready.