Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/297.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Newtonsoft:重写反序列化的默认值_C#_Serialization_Json.net - Fatal编程技术网

C# Newtonsoft:重写反序列化的默认值

C# Newtonsoft:重写反序列化的默认值,c#,serialization,json.net,C#,Serialization,Json.net,我有一个生成的类,如下所示: public partial class ResponseOfImportLeadResponse { /// <summary>Array of LeadsErrors that occurred if the request was unsuccessful</summary> [Newtonsoft.Json.JsonProperty("LeadsErrors", Required = Newtons

我有一个生成的类,如下所示:

public partial class ResponseOfImportLeadResponse
{
    /// <summary>Array of LeadsErrors that occurred if the request was unsuccessful</summary>
    [Newtonsoft.Json.JsonProperty("LeadsErrors", Required = Newtonsoft.Json.Required.Always)]
    [System.ComponentModel.DataAnnotations.Required]
    public System.Collections.Generic.List<LeadsError> LeadsErrors { get; set; } = new System.Collections.Generic.List<LeadsError>();

    /// <summary>Boolean indicating if there are more results in subsequent pages</summary>
    [Newtonsoft.Json.JsonProperty("moreResult", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
    public bool? MoreResult { get; set; }

    /// <summary>Paging token given if the result set exceeded the allowed batch size</summary>
    [Newtonsoft.Json.JsonProperty("nextPageToken", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
    public string NextPageToken { get; set; }

    /// <summary>Id of the request made</summary>
    [Newtonsoft.Json.JsonProperty("requestId", Required = Newtonsoft.Json.Required.Always)]
    [System.ComponentModel.DataAnnotations.Required(AllowEmptyStrings = true)]
    public string RequestId { get; set; }

    /// <summary>Array of results for individual records in the operation, may be empty</summary>
    [Newtonsoft.Json.JsonProperty("result", Required = Newtonsoft.Json.Required.Always)]
    [System.ComponentModel.DataAnnotations.Required]
    public System.Collections.Generic.List<ImportLeadResponse> Result { get; set; } = new System.Collections.Generic.List<ImportLeadResponse>();

    /// <summary>Whether the request succeeded</summary>
    [Newtonsoft.Json.JsonProperty("success", Required = Newtonsoft.Json.Required.Always)]
    public bool Success { get; set; }

    /// <summary>Array of warnings given for the operation</summary>
    [Newtonsoft.Json.JsonProperty("warnings", Required = Newtonsoft.Json.Required.Always)]
    [System.ComponentModel.DataAnnotations.Required]
    public System.Collections.Generic.List<Warning> Warnings { get; set; } = new System.Collections.Generic.List<Warning>();
}
public class OverrideRequiredResolver : DefaultContractResolver
{
    protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization)
    {
        JsonProperty jsonProperty = base.CreateProperty(member, memberSerialization);
        if (jsonProperty.Required == Required.Always)
        {
            jsonProperty.Required = Required.Default;
        }

        return jsonProperty;
    }
}