Why does RestSharp throw an error when deserializing a boolean response?

When I make a request in RestSharp, for example:

var response = client.Execute<bool>(request);

I get the following error:

"Unable to cast object of type 'System.Boolean' to type 'System.Collections.Generic.IDictionary`2[System.String,System.Object]'."

This is a complete HTTP response for each Fiddler:

HTTP/1.1 200 OK
Cache-Control: no-cache
Pragma: no-cache
Content-Type: application/json; charset=utf-8
Expires: -1
Server: Microsoft-IIS/7.5
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Date: Mon, 01 Apr 2013 15:09:14 GMT
Content-Length: 5

false

Everything seems to be kosher with the answer, so what gives?

Also, if I'm doing something stupid with my WebAPI controller, returning a simple value instead of an object, and this will fix my problem, feel free to suggest.

+5
source share
1 answer

RestSharp will only deserialize virtual json. falseinvalid json (according to RFC-4627). The server will require at least the following:

{ "foo": false }

And you will need a class for subsequent deserialization:

public class BooleanResponse
{
    public bool Foo { get; set; }
}
+9
source

All Articles