1

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?

Dan Dinu
  • 32,492
  • 24
  • 78
  • 114
  • For documentation of `MissingMemberHandling` see [here](http://www.newtonsoft.com/json/help/html/DeserializeMissingMemberHandling.htm). – dbc Oct 21 '16 at 20:20

0 Answers0