简体   繁体   English

修改ASP.NET Web API反序列化过程

[英]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.

相关问题 反序列化之前是否可以验证Asp.Net OData Web Api? - Is possible Asp.Net OData Web Api validation before deserialization? asp.net Web-Api JSON字符串反序列化 - asp.net Web-Api JSON string deserialization 在 ASP.NET 中运行单独的进程 核心 Web 最小 API - Running separate process in ASP.NET Core Web Minimal API 运行用于ASP.NET框架的WEB API的过程是什么 - What is the process that run the WEB API for ASP.NET framework ASP.NET Core Web API自动JSON参数反序列化不起作用 - ASP.NET Core Web API Automatic JSON Parameter Deserialization Not Working 在 Asp.Net Core Web API 中反序列化期间未验证用 [DataMember] 修饰的数据 - Data decorated with [DataMember] is not being validated during deserialization in Asp.Net Core Web API 如果类型不匹配,如何使ASP.NET Web API反序列化失败 - How to fail ASP.NET Web API deserialization when types do not match ASP.NET JSON反序列化 - Asp.net json deserialization 如何在ASP .NET MVC中管理Web API控制器的序列化/反序列化 - How to manage serialisation/deserialization of Web api controller in asp .Net mvc ASP.NET Web Api 2 - Internet Explorer:该进程无法访问该文件,因为它正被另一个进程使用 - ASP.NET Web Api 2 - Internet Explorer: The process cannot access the file because it is being used by another process
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM