C
C#2mo ago
Core

✅ NodaTime JSON Serialization

Hello, .NET will parse any date format to DateTime or DateTimeOffset, but what happens if I give NodaTime control over the serialization? Assuming I accept an Instant in the DTO and a request comes in, but the format is not ISO-8601, will it be able to convert any type of date like .NET does, or will it only work with strict types? From the docs:
Between releases 4.0 and 4.5.11, Json.NET introduced automatic date parsing: by default, if the parser detects a value which looks like a date, it will automatically convert it to a DateTime or (optionally) to a DateTimeOffset. In order to give Noda Time control over the serialization, this must be disabled in JsonSerializerSettings or JsonSerializer
Between releases 4.0 and 4.5.11, Json.NET introduced automatic date parsing: by default, if the parser detects a value which looks like a date, it will automatically convert it to a DateTime or (optionally) to a DateTimeOffset. In order to give Noda Time control over the serialization, this must be disabled in JsonSerializerSettings or JsonSerializer
6 Replies
Unknown User
Unknown User2mo ago
Message Not Public
Sign In & Join Server To View
Core
Core2mo ago
I am using System.Text.Json, but NodaTime is still a thord party library with its own date types and the same Json.Net configuration is also valid for System.Text.Json
Unknown User
Unknown User2mo ago
Message Not Public
Sign In & Join Server To View
Core
Core2mo ago
No description
Unknown User
Unknown User2mo ago
Message Not Public
Sign In & Join Server To View
Core
Core2mo ago
Got it, thanks
Want results from more Discord servers?
Add your server