Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RestSharp: Execute<T>() with T having IEnumerable property

Tags:

c#

restsharp

I noticed that using RestSharp :Execute<T>() , when T as below

public class Result
{
    public List<DBData> Data { get; set; }
    public int Total { get; set; }
    public bool Success { get; set; }           
}

It deserialized the JSON from Execute<Result>() correctly into Result object, However when the class has IEnumerable property like below

public class Result 
{
    public IEnumerable<DBData> Data { get; set; }
    public int Total { get; set; }
    public bool Success { get; set; }
}

Execute<Result>() does not fill(deserialize) into the object Result.

I am suspecting it is because of IEnumerable<T> being read only and Restsharp is unable to deserialize data because of that ? Is it the case ?

like image 435
amar_kar Avatar asked Nov 07 '22 17:11

amar_kar


1 Answers

Because RestSharp can not infer the type of the property from the IEnumerable. Extend the existing SimpleJson serializer to use more robust serializer like Json.Net

like image 114
Miguel Avatar answered Nov 14 '22 21:11

Miguel