Actually I'd have to encapsulate since Deserialize<T> is not virtual.
But still pretty easy:
public class NullSupportingJsonDeserializer : IDeserializer
{
public T Deserialize<T>(IRestResponse response)
{
if (response.Content == "null")
{
return default(T);
}
var deserializer = new JsonDeserializer
{
RootElement = this.RootElement,
Namespace = this.Namespace,
DateFormat = this.DateFormat
};
return deserializer.Deserialize<T>(response);
}
public string RootElement { get; set; }
public string Namespace { get; set; }
public string DateFormat { get; set; }
}
However, I notice the JsonDeserializer property no longer exists for
RestClient. Does this mean I need to manually register my
deserializer for all json types?
var client = new RestClient(restUri);
client.RemoveHandler("application/json");
client.RemoveHandler("text/json");
client.RemoveHandler("text/x-json");
client.AddHandler("application/json", new NullSupportingJsonDeserializer());
client.AddHandler("text/json", new NullSupportingJsonDeserializer());
client.AddHandler("text/x-json", new NullSupportingJsonDeserializer());
Thanks.