amar_kar amar_kar - 1 month ago 9
C# Question

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

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 ?

Answer Source

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