C# 10 - Difficulty Using Record Types with JsonSerializerOptions for Custom Date Formats
Hey everyone, I'm running into an issue that's driving me crazy. I'm working on a project and hit a roadblock. I'm having trouble deserializing JSON into a C# record type when my date properties are formatted in a non-standard way. I have a record defined like this: ```csharp public record Event(string Name, DateTime EventDate); ``` The JSON being deserialized looks like this: ```json { "Name": "Sample Event", "EventDate": "2023-10-15T14:30:00Z" } ``` Iām using `System.Text.Json.JsonSerializer` to deserialize it, but I need to handle dates in the format "yyyy-MM-ddTHH:mm:ssZ" specifically. I've tried customizing the `JsonSerializerOptions` like this: ```csharp var options = new JsonSerializerOptions { PropertyNamingPolicy = JsonNamingPolicy.CamelCase, Converters = { new JsonStringEnumConverter() } }; var result = JsonSerializer.Deserialize<Event>(json, options); ``` However, I'm getting a `JsonException: The JSON value could not be converted to System.DateTime.` I suspect that the default deserializer isn't recognizing the date format. Is there a way to specify a custom date format during deserialization with `System.Text.Json`? Are there any converters I should be implementing for this? I've also looked into `JsonConverter<DateTime>` but I'm unsure how to implement it correctly for my scenario. Any suggestions would be greatly appreciated! My development environment is Ubuntu. Any ideas what could be causing this? I'd really appreciate any guidance on this. This is for a application running on Ubuntu 20.04. What are your experiences with this? This issue appeared after updating to C# 3.11. I appreciate any insights! Is this even possible? Thanks, I really appreciate it!