title: Newtonsoft: Override deserialized default value
body: <p>I have a generated class as follows:</p>
  <pre><code>public partial class ResponseOfImportLeadResponse
  {
      /// &lt;summary&gt;Array of LeadsErrors that occurred if the request was unsuccessful&lt;/summary&gt;
      [Newtonsoft.Json.JsonProperty(&quot;LeadsErrors&quot;, Required = Newtonsoft.Json.Required.Always)]
      [System.ComponentModel.DataAnnotations.Required]
      public System.Collections.Generic.List&lt;LeadsError&gt; LeadsErrors { get; set; } = new System.Collections.Generic.List&lt;LeadsError&gt;();
  
      /// &lt;summary&gt;Boolean indicating if there are more results in subsequent pages&lt;/summary&gt;
      [Newtonsoft.Json.JsonProperty(&quot;moreResult&quot;, Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
      public bool? MoreResult { get; set; }
  
      /// &lt;summary&gt;Paging token given if the result set exceeded the allowed batch size&lt;/summary&gt;
      [Newtonsoft.Json.JsonProperty(&quot;nextPageToken&quot;, Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
      public string NextPageToken { get; set; }
  
      /// &lt;summary&gt;Id of the request made&lt;/summary&gt;
      [Newtonsoft.Json.JsonProperty(&quot;requestId&quot;, Required = Newtonsoft.Json.Required.Always)]
      [System.ComponentModel.DataAnnotations.Required(AllowEmptyStrings = true)]
      public string RequestId { get; set; }
  
      /// &lt;summary&gt;Array of results for individual records in the operation, may be empty&lt;/summary&gt;
      [Newtonsoft.Json.JsonProperty(&quot;result&quot;, Required = Newtonsoft.Json.Required.Always)]
      [System.ComponentModel.DataAnnotations.Required]
      public System.Collections.Generic.List&lt;ImportLeadResponse&gt; Result { get; set; } = new System.Collections.Generic.List&lt;ImportLeadResponse&gt;();
  
      /// &lt;summary&gt;Whether the request succeeded&lt;/summary&gt;
      [Newtonsoft.Json.JsonProperty(&quot;success&quot;, Required = Newtonsoft.Json.Required.Always)]
      public bool Success { get; set; }
  
      /// &lt;summary&gt;Array of warnings given for the operation&lt;/summary&gt;
      [Newtonsoft.Json.JsonProperty(&quot;warnings&quot;, Required = Newtonsoft.Json.Required.Always)]
      [System.ComponentModel.DataAnnotations.Required]
      public System.Collections.Generic.List&lt;Warning&gt; Warnings { get; set; } = new System.Collections.Generic.List&lt;Warning&gt;();
  }
  </code></pre>
  <p>I am currently receiving JSON that contains values for <code>Warnings</code>, but upon deserializtion of the JSON into this class I get an empty <code>List</code>. I actually get this for all of the properties of type <code>List</code>. I have a hunch that it's due the fact that there is an explicit declaration of a <code>new System.Collections.Generic.List</code> on each of these properties with an empty <code>List</code>.</p>
  <p>I also see that through the debugger, the <code>new</code> instantiation happens followed by the <code>set</code> called on the other non <code>List</code> properties to confirm my hunch.</p>
  <p>Is there a way to stop this? I cannot edit the generated files since I am worried of re-generation later on.</p>
  <p>I currently have this resolver in place for my <code>JsonSerializerSettings.ContractResolver</code> because the API response I get back does not actually contain the <code>Required.Always</code> properties..</p>
  <pre><code>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;
      }
  }
  </code></pre>