Reputation: 571
I need to change the way OData serializes DateTime
and DateTimeOffset
.
Currently we are using Microsoft.AspNet.OData 5.9.0
By default the format is most likely yyyy-MM-dd'T'HH:mm:ss.FFFFFFzzz
, but I need to have constant number of digits so something like yyyy-MM-dd'T'HH:mm:ss.fffzzz
.
So far I've learned that WebApi OData does not use Newtonsoft.Json
for Json serialization as WebApi does and that it's pretty hard to find some examples of how to change serializer behavior.
Thanks for help!
Upvotes: 2
Views: 1966
Reputation: 340
You can achieve this via creating a customized payload coverter,
Implement a class extends class ODataPayloadValueConverter
Override method public override object ConvertToPayloadValue(object value, IEdmTypeReference edmTypeReference)
Have a check like this in the method if (value is DateTimeOffSet) { return "CustomziedString"; }
Register into your model via setting like model.SetPayloadValueConverter(converter);
Then the payload in response will be shown the DateTimeOffset in your customized way.
Upvotes: 6