currently I'm struggling a little bit with the .NET MVC JSON parser. I've got a model which contains several DateTime properties. This model is POSTed to the server who tries to parse it.
The string which represents the DateTime is perfectly ISO8601 formatted. Example:
2018-11-14T19:14:20.858
or
2018-11-14T18:14:20.858Z
Obviously, the default MVC JSON parser uses DateTime.Parse() without any other parameters. The first example results in a DateTime with Kind = Unspecified while the second one, which should be UTC, results in Kind = Local. Both is not correct.
On the other hand, as soon as I use
DateTime.Parse("...", CultureInfo.InvariantCulture, DateTimeStyles.RoundtripKind)
the result is absolutely perfect.
Now my question to you: Is there a way to either
- Tell the default MVC JSON parser to use DateTimeStyles.RoundtripKind to parse DateTime
- Completely replace the MVC JSON parser by e.g. Newtonsoft.JSON
I'm totally fine with either of the solutions! I'm already using Newtonsoft to serialize my data and ensure DateTime objects are smoothly serialized as ISO8601.
Thank's a lot in advance :)