RestSharp Json format as YYYY-MM-DD / HH:mm:ss
We are using a combination of DateOnly and RestSharp for our API environment.
When serializing the DateOnly object in .Net Framework it comes out as { "Year": 2024, "Month": 9, "Day": 2........}
Is there anyway to get it to serialize as "YYYY-MM-DD"?
AFAIK the latest version of RestSharp uses the System.Text.Json package as its default JSON serialization/deserialization library.
Fortunately, we already have a companion NuGet package Portable.System.DateTimeOnly.Json that contains converters and attributes that you can use with this library. So, you must apply the System.Text.Json.DateOnlyConverterAttribute attribute from this package to your DateOnly properties/fields.
If you use RestSharp in the old way with the Newtonsoft.Json package as a JSON serialization/deserialization library, you have to implement the converter manually. See more information about it in the #71 discussion thread.
@all-contributors please add @deg-mallard for bug
I close this one due to inactivity. @deg-mallard, if you still have questions about RestSharp interoperability, please re-open this issue or create another one with detailed reproducing steps.