【发布时间】:2013-10-22 09:12:59
【问题描述】:
我正在使用 HttpPatch 部分更新对象。为了让它工作,我使用了 OData 的 Delta 和 Patch 方法(这里提到:What's the currently recommended way of performing partial updates with Web API?)。一切似乎都运行良好,但注意到映射器区分大小写;当传递以下对象时,属性将获得更新的值:
{
"Title" : "New title goes here",
"ShortDescription" : "New text goes here"
}
但是当我传递具有小写或驼峰属性的同一对象时,补丁不起作用 - 新值没有通过,所以看起来反序列化和属性映射存在问题,即:“shortDescription”到“简短说明”。
是否存在使用 Patch 忽略区分大小写的配置部分?
仅供参考:
在输出中,我使用以下格式化程序具有驼峰式属性(遵循 REST 最佳实践):
//formatting
JsonSerializerSettings jss = new JsonSerializerSettings();
jss.ContractResolver = new CamelCasePropertyNamesContractResolver();
config.Formatters.JsonFormatter.SerializerSettings = jss;
//sample output
{
"title" : "First",
"shortDescription" : "First post!"
}
但是,我的模型类遵循 C#/.NET 格式约定:
public class Entry {
public string Title { get; set;}
public string ShortDescription { get; set;}
//rest of the code omitted
}
【问题讨论】:
标签: c# api asp.net-mvc-4 odata