I have an Azure Function that receives some JSON from a queue, fx.
{"FromDate":"2020-05-26T07:15:00.3714532+00:00","ToDate":"2020-06-25T07:15:00.3714532+00:00"}
Using System.Text.Json.JsonSerializer
I am trying to de-serialize this JSON into an object of the following type:
public class DateRange
{
public DateTime? FromDate { get; set; }
public DateTime? ToDate { get; set; }
}
The de-serialization:
var dateRange = JsonSerializer.Deserialize<DateRange>(json);
This does not work in Azure - FromDate
and ToDate
are always parsed to the default date 1/1/0001 12:00:00 AM
. The strange thing is that the JSON is created from another Azure Function with JsonSerializer.Serialize(dateRange)
.
But if I run the Azure Function locally it does work.
It seems from the documentation, that the date/time format
"yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'FFFFFFF('+'/'-')HH':'mm"
sent in the JSON is supported (which makes sense because it is created by JsonSerializer.Serialize()
).
Why does it fail to de-serialize my JSON? And why does it work locally but not on Azure?