advanced patterns with JsonSerializer.Serialize in .NET 6 - Missing Nullable Properties
I'm relatively new to this, so bear with me. I've looked through the documentation and I'm still confused about I'm experiencing an scenario while using `JsonSerializer.Serialize` in .NET 6 where nullable properties of my object are not being included in the serialized JSON output. I have a class defined as follows: ```csharp public class Employee { public string Name { get; set; } public int? Age { get; set; } public string Department { get; set; } } ``` When I create an instance of `Employee` with `Age` set to `null` and serialize it like this: ```csharp var employee = new Employee { Name = "John Doe", Age = null, Department = "Sales" }; var json = JsonSerializer.Serialize(employee); ``` I expect the output to include `"Age": null`, but instead, I get: ```json {"Name":"John Doe","Department":"Sales"} ``` I have tried using the `JsonSerializerOptions` with `DefaultIgnoreCondition` set to `JsonIgnoreCondition.WhenWritingNull`, but it seems to have no effect. Hereβs the code I used: ```csharp var options = new JsonSerializerOptions { DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull }; var json = JsonSerializer.Serialize(employee, options); ``` I also checked if the nullable properties were being ignored via attributes, but I haven't added any `JsonIgnore` attributes. This behavior is unexpected as I assumed nullable properties should serialize to `null` if they are not ignored. Is there something I'm missing, or is there a specific configuration I need to apply? Any insights would be greatly appreciated! This is part of a larger application I'm building. What's the best practice here? Thanks for your help in advance!