In WebAPI, I've noticed an inconsistency that is messing with our validation practices. If you send a bad body/payload with a POST in xml, deserialization fails and you get an null pointer. If you send a bad body/payload in JSON, you get an empty object instead. It is misleading and I don't like it. Is there a way to force a null pointer with a failed json deserialization??
UPDATE: I'm not having a deserialization problem. I'm having a behavior problem that seems to be a difference between the DataContractSerializer and the Json.net serializer. When xml fails to deserialize, the payload is null. However, when Json fails to deserialize, it seems that it is instantiating a default instance of the expected payload.
Example of a bad xml payload:

Example of the same call using a bad json payload (payload is not null. instead it is a default instance of the payload class)

e.ErrorContext.Handled = true;: github.com/ASP-NET-MVC/aspnetwebstack/blob/master/src/… should be comereturn GetDefaultValueForType(type);call somewhere... Because of thee.ErrorContext.Handled = true;thejsonSerializer.Deserializewill return an empty object and notnull.