0

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?

ebug
  • 451
  • 3
  • 18

1 Answers1

0

Are you using a queue which is bonded as an input to your function (and triggers it)? Could you show how you write the serialized string to queue and then how you read it from the queue before deserialization? Are you sure that the string which is taken from the message looks exactly like in your example? I am asking because the messages in queues bound to functions are expected to be base64 encoded which causes a lot of issues if you forget about this. And since it works locally, I would blame the transport mechanism (queue) for changing the behavior.

Simon
  • 368
  • 1
  • 4
  • 9
  • After my last deploy to Azure everything works as expected. I am not sure what fixed it but it is fixed now - thanks for trying to help, anyway. – ebug Jun 26 '20 at 06:04