I'm writing a custom Json serializer to improve the perf of my service. And yes, I did consider Json.NET, servicestack, DataContractJsonSerializer, etc before I made the decision. My objects are flat with simple .NET types and I wanted to avoid the overhead of a much bigger library.
Anyways, here is where I run into a small problem. I have the code to serialize DateTime -
var epoch = new DateTime(1970, 1, 1, 0, 0, 0);
sb.Append("\"\\/Date(");
SerializeNumber((time - epoch).TotalMilliseconds, sb);
sb.Append(")\\/\"");
And this works great, except I can't quite get it to match the default .NET Json serializer in the output.
.NET serializer
"\\/Date(1328057884253)\\/\"
Custom serializer
"\\/Date(1328057884253.04)\\/\"
Hmm, so I tried making my conversion less precise and switching to (int)TotalSeconds instead of milliseconds and that gives me this -
.NET serializer
"\\/Date(1328054810067)\\/\"
Custom serializer
"\\/Date(1328054810)\\/\"
I'm guessing that this wouldn't be a big deal but it would be nice to get my unit tests passing against the default .NET serializer just for sanity. Any ideas?
Thanks.