Doesn't ASP.NET Web Api Model Binding Use Newtonsoft (JSON.NET)

本小妞迷上赌 提交于 2020-01-26 00:59:46

问题


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?

来源:https://stackoverflow.com/questions/41793370/doesnt-asp-net-web-api-model-binding-use-newtonsoft-json-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!