I'm trying to deserialize this json
{
"state": "enabled"
}
to
class Setting
{
[JsonProperty(PropertyName = "state")]
public string State { get; set; }
}
I have my Web API controller method:
public async Task<HttpResponseMessage> SetSetting([FromBody] Setting setting)
{
// not important
}
I would like to force deserialization to fail in case I receive the following json paylod in the request:
{
"state": "enabled",
"extra_key": "extra_value"
}
I 've tried setting up this in the webApi config:
config.Formatters.JsonFormatter.SerializerSettings.CheckAdditionalContent = true;
However, this works only if I have additional content at the very end of the payload such as:
{
"state": "enabled",
}, "extra"
How can I force deserialization to fail in case I'm getting additional json properties?