-
Notifications
You must be signed in to change notification settings - Fork 2.1k
ModelState BadRequest inconsistent behaviour #5672
Comments
This appears to just be how Json.NET is reporting the invalid JSON syntax to MVC's formatter. In general it can be difficult to predict how invalid syntax is interpreted because it can be ambiguous. I'm guessing that the extra @JamesNK any thoughts on this? |
Json.NET serializes what you give it. If you give it a dictionary with an empty string key then that is what it will serialize. |
@JamesNK this is about deserialization error behavior for invalid JSON. |
E.g. this JSON: {
"name": "sample3",
"cost": 10000000000000000000000000",
} Is clearly invalid for at least three reasons:
|
@Eilon @JamesNK Sample 4: This one seems like a bug. An empty key appears (instead of int out of range error) POST http://localhost:5000/api/v1/items
content-type: application/json
{
"name": "sample4",
"cost": 10000000000000000000000000
} Response: {
"": [
"The input was not valid."
],
"cost": [
"The input was not valid."
]
} The exception logger, logs following error in console:
|
Hi, we discussed this and we have an idea that would help mitigate this somewhat. See this issue for more details: #5705 But for the specific issue here, ultimately ASP.NET Core is just processing the errors returned by Json.NET and it would be risky to change the behavior in how the errors are processed, so we are closing this issue. |
I have a simple model:
Inside controller:
Now, for following three incorrect sample inputs I get following responses:
Sample #1:
Response:
Sample #2:
Response:
Sample #3: This one seems like a bug. An empty key appears (instead of int out of range error)
Response:
The text was updated successfully, but these errors were encountered: