This project has moved and is read-only. For the latest updates, please go here.

IsoDateTimeConverter and Deserializing to a Dictionary

Apr 23, 2010 at 9:18 PM


Given sample code below, a date value in a dictionary serialized with IsoDateTimeConverter, ends up being a String when deserialized.

I know that it is not an error as there is no datetime type in JSON spec and it is serialized to a string, but wondering

if there is any way to get same type back when deserializing, by some converter, setting etc?

var a = new Dictionary<string, object>();
a["date"] = DateTime.Now;
var x = JsonConvert.SerializeObject(a, new Newtonsoft.Json.Converters.IsoDateTimeConverter());
var y = JsonConvert.DeserializeObject<Dictionary<string, object>>(x, new Newtonsoft.Json.Converters.IsoDateTimeConverter());
y["date"].GetType().Name.ToString() // returns String