Restsharp, DateTime and UTC converted to Local Time when deserialized

2,562 views
Skip to first unread message

Ra Rodriguez

unread,
Oct 26, 2013, 8:26:42 PM10/26/13
to rest...@googlegroups.com
Hello,

I inherited a project in Xamarin which uses the RestSharp component to consume the webapi exposed for the mobile devices.
When de-serializing DateTime properties like:

"Start":"2013-10-18T22:13:55Z"

This UTC value is converted to local time.

After searching for a while I came up to this post, which is using JSON.NET for the Deserialization w/o experiencing the issue.


Is there a work around this, other than the one suggested in the answer?
I see I can set the JsonSerializer and JsonDeserializer in the request, which have to implement ISerializer and IDeserializer respectively; is there any implementation using JSON.NET out there?

Thanks!
R.

Ra Rodriguez

unread,
Oct 28, 2013, 3:56:51 PM10/28/13
to rest...@googlegroups.com
Any ideas?

Rui Ribeiro

unread,
Oct 28, 2013, 4:16:29 PM10/28/13
to rest...@googlegroups.com
You can use the JSON.NET deserializer rather easily. In a recent project, I just used it, as the native deserializer was failing:

Here is an example:

                var response = client.Execute(request);

T newData = JsonConvert.DeserializeObject<T>(response.Content.ToString());

That should do it.

Ra Rodriguez

unread,
Oct 28, 2013, 4:59:05 PM10/28/13
to rest...@googlegroups.com
Thanks Rui, was expecting to continue using the Typed api and plug a deserializer based on JSON.NET.

Rui Ribeiro

unread,
Oct 28, 2013, 5:42:59 PM10/28/13
to rest...@googlegroups.com
I do this inside a method with this signature:

public T Execute<T>(RestRequest request,String args) where T : new()
{...
}

So, from an external point of view, you lose nothing. It's a simple solution.
Reply all
Reply to author
Forward
0 new messages