user3190036
user3190036

Reputation: 533

How to configure aspnet core json serialization

I reported this issue https://github.com/dotnet/runtime/issues/48816 and the developer that responded posted code explaining how to manually deserialize the function argument. Asp is supposed to have an automated system for this however. So if my function definition looks like:

[Authorize]
[HttpPost]
public async Task<IActionResult> Post(Session session)
{
...

then I am supposed to be able to just use session as a variable from that point without any special deserialization step. This suggests to me that there must be a way to set JsonSerializerOptions(JsonSerializerDefaults.Web) somewhere in a more global way so that it can consume the post data it is getting. Alternatively there might be a different way to serialize the post data differently on the client so that it does not get converted to camel case.

The main question is: what is the correct way to serialize and deserialize data objects for asp.net-core?

Upvotes: 0

Views: 170

Answers (1)

Jason Pan
Jason Pan

Reputation: 22082

To Reproduce

enter image description here

enter image description here

Thanks for Roar S's comment, use [FromBody], it works.

enter image description here

enter image description here

Upvotes: 1

Related Questions