Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET Web API Handles Two Integers Differently

I have a model in my Web API project that accepts two integers:

public int ParentId { get; set; }
public int ChildId { get; set; }

While testing the API, I tested sending crazy big numbers (like you do) in the JSON message:

{
    ParentId: 333333333333333333333333333333333333333,
    ChildId: 1
}

In the above case, the ParentId becomes 0. Happy days.

In the following case, where the ChildId is passed with the exact same crazy big number, the whole model ends up null.

{
    ParentId: 1,
    ChildId: 333333333333333333333333333333333333333
}

Why does this not simply cause ChildId to become 0 as the ParentId did?

like image 553
Fenton Avatar asked Jun 01 '26 00:06

Fenton


1 Answers

You can solve this issue by appending a comma. Neat</sarcasm>.

{
    ParentId: 2,
    ChildId: 333333333333333333333333333333333333333,
}

So it does indeed look like a deserializer bug as noted by @djikay in the comments above.

Update: The issue has been fixed: https://github.com/JamesNK/Newtonsoft.Json/issues/315

like image 130
Fenton Avatar answered Jun 02 '26 21:06

Fenton



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!