Reputation: 726
I'm unabled to get a value for a key that has a .
in it when using RestSharp's DeserializeAsAttribute.
Here's my JSON:
{
".issued": "Wed, 24 Jun 2015 20:59:57 GMT",
".expires": "Wed, 08 Jul 2015 20:59:57 GMT"
}
Model I'm deserializing:
class TokenModel
{
[DeserializeAs(Name = ".issued")]
public DateTime Issued { get; set; }
[DeserializeAs(Name = ".expires")]
public DateTime Expires { get; set; }
}
Debugging:
GetToken() - success - issued: 1/1/0001 12:00:00 AM
GetToken() - success - expires: 1/1/0001 12:00:00 AM
I also have the RestRequest.DateFormat
set to:
request.DateFormat = "ddd, dd MMM yyyy HH':'mm':'ss 'GMT'";
I've followed the https://github.com/restsharp/RestSharp/wiki/Deserialization docs as best I can without any luck.
Upvotes: 1
Views: 279
Reputation: 211
I would also like to figure this out. I had to parse the response content manually...
Regex IssuedRegex = new Regex(@"\""\.issued\"":\s*\""([^\""]+)\""");
Regex ExpiresRegex = new Regex(@"\""\.expires\"":\s*\""([^\""]+)\""");
var response = authClient.Execute<AccessToken>(request);
AccessToken = response.Data;
// workaround for bug in RestSharp
var im = IssuedRegex.Match(response.Content);
if (im.Success)
AccessToken.Issued = DateTime.ParseExact(im.Groups[1].Value, "R", CultureInfo.InvariantCulture);
var em = ExpiresRegex.Match(response.Content);
if (em.Success)
AccessToken.Expires = DateTime.ParseExact(em.Groups[1].Value, "R", CultureInfo.InvariantCulture);
Upvotes: 1