C# - implementing Serialization of Nullable Properties in Newtonsoft.Json
This might be a silly question, but I'm performance testing and This might be a silly question, but I've been struggling with this for a few days now and could really use some help... I'm having trouble serializing an object that contains nullable properties using Newtonsoft.Json. In my model, I have a property defined as `public int? Age { get; set; }`. When I serialize an object of this model with `null` values, I'm expecting it to output `"Age": null` in the JSON. However, I'm seeing that the property is completely omitted from the output if it's `null`. I've tried setting `NullValueHandling` to `Include`, but it doesn't seem to have any effect. Here's a snippet of my code: ```csharp public class Person { public string Name { get; set; } public int? Age { get; set; } } var person = new Person { Name = "John Doe", Age = null }; var json = JsonConvert.SerializeObject(person, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Include }); ``` The resulting JSON is: ```json {"Name":"John Doe"} ``` I've also checked the version of Newtonsoft.Json I'm using, which is 13.0.1. Is there a reason why the nullable property isn't being included in the serialized output, and how can I ensure that it appears as `"Age": null`? Any help would be appreciated! Any ideas what could be causing this? My development environment is Windows. What's the best practice here? The stack includes C# and several other technologies. Any advice would be much appreciated. Any feedback is welcome!