0

As far as I understand, Web Api uses Newtonsoft (JSON.NET) serializer/deserializer when model binding. But when I use [JsonProperty(Required = Required.AllowNull)] attribute for a model property, it does not work. I omit the property in JSON but model binder does not throw exception or make the ModelState.IsValid false. My questions are:

  1. Why does it not work if Web Api is using Json.Net? Is there a simple solution like a configuration change?
  2. If I have to use a custom model binder in order to use a deserializer that respects such attributes, should my model binder just implement the IModelBinder interface or should it inherit from some default model binder implementation?
2
  • 1
    No; it uses the DataContract serializer. Commented Jan 22, 2017 at 16:35
  • @SLaks How can I make it use Json.Net? Commented Jan 22, 2017 at 16:44

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.