I have an ASP.NET Core Web API project, with a controller and a controller method that has a parameter [FromBody] MyDTO dto
.
When I call this method via REST request with an empty body, the framework returns a ProblemDetails
object with something like this:
{
"type": "https://xyz/Status-400",
"title": "Bad Request",
"status": 400,
"errors": {
"": [
"A non-empty request body is required."
]
},
"trace-id": "..."
}
which is absolutely understandable.
But: when I call it with a request body like “[]” which is not a jsonObject
but an array (whereas the controller method needs a single object), the ProblemDetails
response object looks something like this:
{
"type": "https://xyz/Status-400",
"title": "Bad Request",
"status": 400,
"errors": {
"$": [
"The input was not valid."
]
}
},
"trace-id": "..."
}
which again is somewhat “okayish” if one can assume that $
means request body (this message comes directly out of the ModelStateDictionary
).
My questions are:
- How can the name of the key
$
be changed? - Should it be changed?
1