[IMPLEMENTED] Squidex.ClientLibrary: Json serializes dates to incorrect format

It seems a bug in the ClientLibrary. It’s not possible to save an object with a DateTime field because of incorrect serialized DateTime format.

Example of serialized DateTime: “2019-06-30T00:00:00”. And it’s not ISO8601

A workaround is to create and use separate DateTimeConverter for DateTime fields instead of InvariantConverter with correct DateTimeFormat.

Thx, will be fixed today.

Do you have a small example?

F.E. changes to InvariantConverter

 public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
                if (value is DateTime)
                    var converter = new IsoDateTimeConverter
                        DateTimeFormat = "yyyy'-'MM'-'dd'T'HH':'mm':'ss'Z'"

        serializer.Serialize(writer, value);

This should be the default:

Note Note
From Json.NET 4.5 and onwards dates are written using the ISO 8601 format by default, and using this converter is unnecessary.

IsoDateTimeConverter serializes a DateTime to an ISO 8601 formatted string: “2009-02-15T00:00:00Z”

The IsoDateTimeConverter class has a property, DateTimeFormat, to further customize the formatted string.

The reason is that your datetime is actually not UTC. It is actually not a bug but I can improve it.

I have added the functionality to convert datetime to utc automatically: https://github.com/Squidex/squidex-samples/commit/fd1bd57a637d16cc894b4eba9d1cb6d3d23be4fc

3.1. of the library is on its way and already pushed to nuget.

Thanks. now it works as it should

1 Like