DateTime.Ticks Not Serializing/Deserializing properly


We are saving a DateTime as ticks (long) in the db.

We are noticing that when it is retrieved back it is off. Any idea why? It the JSON deserializer/serializer doing this?


@ibrahim.hadad -

Yes, most likely this is the serializer. You can apply the same settings and configurations to the serializer that you can with NewtonSoft, so you should be able to make it behave as you need it to with a bit of customization.



What do you mean by "off’?



What I meant was that what was inserted was not matching what we were retrieving.

How? Is there any documentation on this so that I can read up on it?

Thanks again, for all your help.



@ibrahim.hadad -

That’s interesting, I could see where there could be conversion issues between DateTime and ticks, but the actual value shouldn’t be changing if stored as a long. Perhaps you could create a small example project and post to a ticket on Jira? Use the “Create” button.

As for customizing the DefaultSerializer ctor takes two parameters for JsonSerializerSettings; deserialization settings and serialization settings. You can use any of the NewtonSoft features, like overriding the ContractResolver, to change how serialization/deserialization takes place. You then assign a factory method like this to apply the settings:

var config = new ClientConfiguration{
    Serializer = ()=>new DefaultSerializer(new JsonSerializerSettings(), new JsonSerializerSettings())