The DataContractJsonSerializer does not properly handle DateTime values. It blatantly disregards the precedent that has been established in the rest of .Net framework for proper use of the .Kind property.
More importantly, it completely disregards any offset passed in, choosing UTC if no offset, and Local time if ANY offset. This is very bad, because the offset and the date value are related, and ignoring the offset can provide the wrong date!
- A DateTime with a DateTimeKind.Local should be serialized to JSON with the local offset. This is working ok.
- A DateTime with a DateTimeKind.Utc should be serialized to JSON without an offset. This is working ok.
*** There should be some way to indicate how a DateTime with a DateTimeKind.Unspecified should be serialized to JSON. It currently assumes this is to be treated as local time, which might not be the case.
- A JSON date without an offset should be treated as DateTimeKind.Utc. This is working ok.
*** A JSON date with an offset should be treated as DateTimeKind.Unspecified, and the provided offset should be applied. Instead, it is using as DateTimeKind.Local and applying the local offset.
*** A JSON date with an invalid offset (not in +HHMM or -HHMM form) should throw an exception. This is not occurring.
This should be raised as a critical issue. Anyone using the DataContractJsonSerializer for its intended use will run into these problems in any kind of global web application.