Intermittent Serialization implementing System.Text.Json in .NET 6 - JsonException on Nullable Properties
I've encountered a strange issue with I'm performance testing and I've searched everywhere and can't find a clear answer. I'm experiencing intermittent `JsonException` errors when serializing objects using `System.Text.Json` in .NET 6. The behavior message states: `The JSON value could not be converted to System.String.` This usually occurs with objects that have nullable properties. Here's a simplified version of my model: ```csharp public class User { public int Id { get; set; } public string Name { get; set; } public string? Email { get; set; } } ``` When I serialize an instance of `User`, it works fine if all properties are set, including `Email`. However, if `Email` is `null`, I intermittently get the `JsonException`, particularly when the `User` object is part of a larger object. For example: ```csharp public class UserProfile { public User User { get; set; } public DateTime LastActive { get; set; } } ``` When I serialize a `UserProfile` instance like so: ```csharp var profile = new UserProfile { User = new User { Id = 1, Name = "John", Email = null }, LastActive = DateTime.Now }; var json = JsonSerializer.Serialize(profile); ``` I sometimes get the `JsonException` when `Email` is `null`. I've already tried setting `JsonSerializerOptions.DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull;`, but it doesn't seem to resolve the scenario completely. Is there a specific configuration or pattern I should follow to handle null properties consistently without throwing exceptions? Any insights or examples would be greatly appreciated. This is part of a larger API I'm building. Has anyone else encountered this? I recently upgraded to C# 3.9. Has anyone dealt with something similar? I'm open to any suggestions. Thanks, I really appreciate it!