Here is a scenario I faced last week:
I sent an array of JSON objects to a WebAPI method with a signature like the following:
void Post(IEnumerable<ItemViewModel> items)
An example of the JSON array might look like (I've removed most of the properties for brevity):
[{ size: 1 },
{ size: 1.5 },
{ size: 2 },
{ size: 3 },
{ size: 1.25 }]
The View Model was something like the following (most properties removed for brevity):
public class ItemViewModel
{
public int Size { get; set; }
}
The problem was that ItemViewModel's Size property is of type "int" and some of the JSON object's size properties were of type "double".
WebAPI didn't see the objects as a match for the type ItemViewModel, but it failed silently and still deserialized the other objects in the collection, just ignoring the ones that didn't match exactly.
Is there any setting/configuration point or other way to have WebAPI throw an exception or log a warning when this happens?