scenarios Deserializing JSON with Nullable Properties in C# 10 - Invalid Cast handling
I'm working with an scenario while deserializing a JSON object into a C# class that contains nullable properties... Specifically, I'm using Newtonsoft.Json version 13.0.1 to handle the deserialization, and I'm getting an `InvalidCastException` whenever the JSON does not contain a value for a nullable property. Here's the JSON I'm working with: ```json { "name": "John Doe", "age": null, "email": "john.doe@example.com" } ``` And this is my C# model: ```csharp public class User { public string Name { get; set; } public int? Age { get; set; } public string Email { get; set; } } ``` When I try to deserialize it using the following code: ```csharp string json = "{\"name\": \"John Doe\", \"age\": null, \"email\": \"john.doe@example.com\"}"; User user = JsonConvert.DeserializeObject<User>(json); ``` I receive the following exception: ``` Unhandled exception. Newtonsoft.Json.JsonSerializationException: behavior converting value null to type 'System.Int32'. ``` I've tried checking the JSON to ensure it's formatted correctly, and I've also confirmed that `Age` is defined as a nullable integer (int?). However, it seems the deserializer is not handling the `null` value appropriately. I've also tried using `JsonSerializerSettings` with `NullValueHandling` set to `Ignore`, but that didn't resolve the scenario either. How can I successfully deserialize this JSON into my User class without working with an exception? Any help or suggestions would be greatly appreciated! For context: I'm using C# on Linux.