OkObjectResult with generic type parameter
- Dominant language
- C#
- Stars
- 38.4k
- Forks
- 10.9k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 281
Description
### Is there an existing issue for this?
- [X] I have searched the existing issues
### Is your feature request related to a problem? Please describe the problem.
I am a bit perplexed that issue #31396 was closed with the simple response "there is nothing we can do about it" as it seems like it is an issue that is very messy to work around. Please correct me if I am missing something.
The root of the problem described there is that ASP.NET uses `JsonSerializer.Serialize` for serializing `OkObjectResult`s.
EF Core returns proxies of some types with some additional properties that are unwanted in the resulting JSON.
Because `Serialize` is used instead of `Serialize`, these properties are not ignored as they lack the `[JsonIgnore]` attribute (which seemingly cannot be added either as an EF Core maintainer acknowledged this issue without bringing this up as a possible solution).
### Describe the solution you'd like
As long as I am not missing something: would it technically be possible to add an additional `OkObjectResult` class that uses `T` rather than `object` (and subsequently `JsonSerializer.Serialize` rather than `JsonSerializer.Serialize`)?
We could then use
```cs
MyType proxiedValue = dbSet.Find(...);
return Ok(proxiedValue);
```
in the controller.
### Additional context
I know that there were other issues suggesting this, but they were closed because multiple people think #8535 would be a better solution.
As I am not sure about whether this would solve this issue as well, I am going to bring this up again.
Contributor guide
Assessment
This issue has not been assessed yet.