We use the Newtonsoft Json converter to deserialise API requests. As we don't want to receive data/members which are not part of the request class in the BackEnd, we set SerializerSettings.MissingMemberHandling
to MissingMemberHandling.Error
:
services.AddControllers().AddNewtonsoftJson(a =>
{
a.SerializerSettings.MissingMemberHandling = MissingMemberHandling.Error;
}
But instead of receiving an Exception, we end up with a 'null' request object for the API-call:
Why don't we get an Exception?
I found the problem: my controller was configurered like this:
Since everything was working as expected before we added the missing member setting, I did not think of the missing attribute
[ApiController]
. Adding this, made this controller act like the others regarding the Json serialisation!To be sure this isn’t forgotten, we wrote a test which checks all controller classes for this attribute.