This project is read-only.


DateTime precision


fastJSON couldn't serialize DateTime well. I know there is old json spec that has YYYY-MM-DDThh:mm:ssZ but it isn't correct for a DateTime object. For example this test will fail:
var dateTime = new DateTime(2013, 1, 1, 1, 1, 1, 1);
var jsonStr = JSON.ToJSON(dateTime);
Assert.AreEqual(dateTime, JSON.ToObject<DateTime>(jsonStr);
Because it has milliseconds. Also I've tried to register custom type but it also failed:
var a = new DateTime(2013, 01, 01, 01, 01, 01, 01);
data => 
data => {
long binary;
return long.TryParse(data, out binary) ? DateTime.FromBinary(binary) : default(DateTime); 
Because it doesn't call serializer delegate that I've implemented above.
Closed Jul 15, 2016 at 3:12 PM by MGholam


MGholam wrote Sep 5, 2014 at 2:48 PM

  • The custom serializer is primarily for non-standard types and you can't override ones already defined.
  • I have had requests for millisecond resolution in datetime and while the specs does not explicitly say but there seems to be general consensus about it.
I will add it in the near future.

oruchreis wrote Sep 8, 2014 at 9:22 AM

Thanks a lot, I'll wait that. it will be our daily use json serializer in the next deployment of our project. We gave up servicestack json because of licensing and depending on DataContractAttribute.