At WebAPI, I noticed an inconsistency that messes with our validation methods. If you send a bad body / payload using POST in xml, deserialization fails, and you get a null pointer. If you send a bad body / payload to JSON, you get an empty object instead. This is misleading and I don't like it. Is there a way to force a null pointer with unsuccessful json deserialization?
UPDATE: I have no problem of deserialization. I have a behavior issue, which seems to be the difference between the DataContractSerializer and the Json.net serializer. When xml does not deserialize, the payload is zero. However, when Json does not deserialize, it seems to create an instance of the expected default payload.
An example of a bad xml payload:

An example of the same call using a bad json payload (the payload is not null but the default instance of the payload class)

source
share