RestEase icon indicating copy to clipboard operation
RestEase copied to clipboard

Using Task<Response<T>> when T is a string does not work.

Open StefH opened this issue 3 years ago • 2 comments

Description Using Task<Response<T>> when T is a string does not work.

To Reproduce

public interface ITest
{
    Task<string> CallGoogleAsync(CancellationToken token); // works

    Task<Response<string>> CallGoogleAsync(CancellationToken token); // throws exception
}

The reason is probably that that the T in the second example is always deserialized as JSON, which fails if the string is just a string like "abc".

Version Info

  • RestEase version: latest
  • Target framework version: all

StefH avatar Jul 07 '22 18:07 StefH

Fair point. I guess the same also applies to Response<Stream> (and also I suppose Task<HttpResponseMessage>, although I'm not sure there's much point in that).

I'm somewhat minded to just let the ResponseDeserializer handle bare strings. We can have a property on the deserializer to say whether it handles raw strings or not to avoid backwards compat issues, although I suppose there's still a problem where someone might have written a deserialize specifically for Response<T>, which intentionally handles raw strings.

canton7 avatar Jul 07 '22 20:07 canton7

Ah no, Response<Stream> makes no sense, as it ends up being read as a string anyway.

canton7 avatar Jul 07 '22 21:07 canton7