Reputation: 16129
My rest service uses ISO 8601 as the date format for all requests and responses. Is there a way to set this on the RestClient
or do I need to set it on each individual RestRequest
?
Upvotes: 2
Views: 5236
Reputation: 11495
It doesn't look like there's any built in ability to do so. Newtonsoft.Json provides an IsoDateTimeConverter that can do the serialization you are looking for. In order to use it for serialization, I think you would need to mostly duplicate the RestSharp.Serializers.JsonSerializer in your own ISerializer that does almost exactly what the RestSharp version does, but tweaksthe NewtonSoft.Json.JsonSerializer.Converters property in the instance created here and adds/replaces the date/time converter.
As far as deserialization, you should be able to set the IDeserializer.DateFormat property on a new JsonDeserializer and setting that as your handler:
client.AddHandler ("application/json", new JsonDeserializer() { DateFormat = "yyyy-MM-ddTHH\:mm\:ss.fffffffzzz" });
Upvotes: 3