RestSharp deserialize JSON content(represent an object contains an byte array) error

Yan Zhengshan picture Yan Zhengshan · Jun 5, 2012 · Viewed 12.1k times · Source

The Client side receives a formal JSON content "{\"Id\":[1,2,3],\"Size\":56}", but get an error in deserialization the byte array.

1 Error occurs in the statement below

IRestResponse<key> response = client.Execute<key>(request);

2 Error message is "No parameterless constructor defined for this object."

3 The object class in client size is the same as it's in server side:

public class key
{
    public byte[] id { get; set; }
    public int Size { set; get; }
}

4 I've tried passing object that contains string and integer by JSON format and that's all fine but byte array.

Answer

user3111679 picture user3111679 · Dec 17, 2013

JsonDeserializer from RestSharp can not deserialize array. Instead of byte[] use List<byte>. For more information see https://github.com/restsharp/RestSharp/wiki/Deserialization