[英]Modify ASP.NET Web API deserialization process
I created a Webserver based on the OWIN / Katana. 我基于OWIN / Katana创建了一个Web服务器。 Currently I have problems about understanding the JSON deserialization process... 目前,我在理解JSON反序列化过程方面遇到问题...
This is the simple POST-Method: 这是简单的POST方法:
public IHttpActionResult Post([FromBody] Person person) {
// do some stuff
return Ok();
}
Now the question: Why are all Getters of the Model called by default, also if there are attributed as "JsonIgnore" or no "DataMember". 现在的问题是:为什么默认情况下会调用所有模型的Getters,即使属性名称为“ JsonIgnore”或没有“ DataMember”也是如此。
Model: 模型:
[DataContract]
public class Person
{
private string firstName;
//This property-getter should not be called
public string FirstName{
get {
return firstName;
}
set {
firstName = value;
}
}
//This property-getter should be called
[DataMember]
public string LastName { get;set; }
}
Is is possible to change this process? 是否可以更改此过程?
Solved. 解决了。
I detected that the getter is called during Web API model validator (see class "DefaultBodyModelValidator") 我检测到在Web API模型验证器中调用了getter(请参阅类“ DefaultBodyModelValidator”)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.