My Json Date Lost Its Offset
I was using NewtonSoft like so many of us for Json Serialization and Deserialization. In this case I was trying to make sure our DateTimes were being returned in a proper ISO8601 format, defaulting to UTC unless a flag was set. If the flag was set it would then use the offset associated with a customer’s location, never to use the browser’s offset.
Sadly it was always rendering in Postman and SoapUI in my local time zone. Even when I would debug through the code, the return Ok(jsonObject); had the expected time zone and format.
While we serialized out object with a JsonSerializerSettings object we were not using one when we deserialized that string to be returned. Our object used only two settings;
- ContractResolver = new CamelCasePropertyNamesContractResolver()
- DateParseHandling = DateParseHandling.None
Once I added using our JsonSerializerSettings object to the final deserialize the dates were rendered properly in Postman and SoapUI.
var jsonObject = JsonConvert.DeserializeObject(tempString, jsonSerializerSettings);