using System.ComponentModel;
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Populate)]
[DefaultValue("Company")]
public string Company { get; set; }
public decimal Amount { get; set; }
public bool Paid { get; set; }
public DateTime? PaidDate { get; set; }
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Populate)]
public int FollowUpDays { get; set; }
public string FollowUpEmailAddress { get; set; }
public static void Main()
Invoice invoice = new Invoice
FollowUpEmailAddress = string.Empty,
string included = JsonConvert.SerializeObject(invoice, Formatting.Indented, new JsonSerializerSettings { });
Console.WriteLine(included);
string raw = "{ \"Company1\": \"Acme Ltd.\", \"Amount\": 50.0, \"Paid\": false, \"PaidDate\": null, \"FollowUpDays\": 30, \"FollowUpEmailAddress\": \"\" }";
string ignored = JsonConvert.SerializeObject(invoice, Formatting.Indented, new JsonSerializerSettings { DefaultValueHandling = DefaultValueHandling.Ignore });
Console.WriteLine(ignored);
var settings = new JsonSerializerSettings();
settings.NullValueHandling = NullValueHandling.Ignore;
var myObj = JsonConvert.DeserializeObject<Invoice>(raw, settings);
Console.WriteLine(myObj.Company ?? "null");