title: Json.NET: How to make DefaultValueHandling only apply to certain types?
body: <p>I have a custom class that looks like this:</p>
  
  <pre><code>public class PartnerLoginOptions
  {
      public string Username { get; set; }
      public string Password { get; set; }
      public string DeviceModel { get; set; }
      public string Version { get; set; }
  
      public bool? IncludeUrls { get; set; }
      public bool? ReturnDeviceType { get; set; }
      public bool? ReturnUpdatePromptVersions { get; set; }
  }
  </code></pre>
  
  <p>I'd like to ignore any <code>bool?</code> members with default values when serializing, but keep strings with null values. For example, if I had an object like this</p>
  
  <pre><code>var options = new PartnerLoginOptions
  {
      Username = null,
      Password = "123",
      IncludeUrls = null,
      ReturnDeviceType = true
  };
  </code></pre>
  
  <p>Then serializing would result in this:</p>
  
  <pre><code>{
      "username": null,
      "password": "123",
      "deviceModel": null,
      "version": null,
      "returnDeviceType": true
  }
  </code></pre>
  
  <p>Here is the code I have so far:</p>
  
  <pre><code>var settings = new JsonSerializerSettings
  {
      ContractResolver = new CamelCasePropertyNamesContractResolver(),
      DefaultValueHandling = DefaultValueHandling.Ignore // this applies to strings too, not just bool?
  };
  
  return JsonConvert.SerializeObject(options, settings);
  </code></pre>
  
  <p>Is there any way to do this without individually tagging each <code>OptionalBool</code> property with <code>[JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]</code>? Thanks.</p>