Unexpected Behavior with Custom JSON Serialization in .NET 6 - Missing Properties
I need help solving I'm stuck on something that should probably be simple. I'm encountering unexpected behavior with JSON serialization in .NET 6 when using a custom JSON converter. I have a class `Person` with properties `FirstName`, `LastName`, and `Age`, but when I serialize an instance of this class, the `Age` property is missing from the output. Here's the code I've implemented for the custom converter: ```csharp public class Person { public string FirstName { get; set; } public string LastName { get; set; } public int Age { get; set; } } public class PersonConverter : JsonConverter<Person> { public override void Write(Utf8JsonWriter writer, Person value, JsonSerializerOptions options) { writer.WriteStartObject(); writer.WriteString("first_name", value.FirstName); writer.WriteString("last_name", value.LastName); // Missing serialization for Age writer.WriteEndObject(); } public override Person Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) { // Deserialization logic here } } ``` When I serialize an instance of `Person`, I expect to see all properties in the JSON output: ```csharp var person = new Person { FirstName = "John", LastName = "Doe", Age = 30 }; var options = new JsonSerializerOptions { WriteIndented = true }; string json = JsonSerializer.Serialize(person, options); Console.WriteLine(json); ``` The output I get is: ```json { "first_name": "John", "last_name": "Doe" } ``` I have confirmed that the `Age` property is being set correctly before serialization. Iโm wondering if thereโs something Iโm missing in my custom converter or if itโs a configuration issue with the `JsonSerializerOptions`. Has anyone else faced this issue, or does anyone have insights on why the `Age` property is not being serialized? I'm working on a service that needs to handle this. Is there a better approach? I'm on Ubuntu 22.04 using the latest version of C#. What are your experiences with this?