[MSA] (2/?) Bug fix: ClassCastException

This commit is contained in:
khanhduytran0 2020-12-10 17:03:14 +07:00
parent 4bd35a10be
commit 9a8e961795

View File

@ -25,8 +25,14 @@ public class HttpResponse<T>
} }
public T body() throws IOException { public T body() throws IOException {
Class<T> type = (Class<T>) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0]; if (statusCode() >= 200 && statusCode() < 300) {
if (type.isAssignableFrom(String.class)) { return (T) Tools.read(mRequest.mBuilder.getBase().getInputStream());
} else {
return (T) Tools.read(mRequest.mBuilder.getBase().getErrorStream());
}
/*
if (T instanceof String) {
if (statusCode() >= 200 && statusCode() < 300) { if (statusCode() >= 200 && statusCode() < 300) {
return (T) Tools.read(mRequest.mBuilder.getBase().getInputStream()); return (T) Tools.read(mRequest.mBuilder.getBase().getInputStream());
} else { } else {
@ -35,5 +41,6 @@ public class HttpResponse<T>
} else { } else {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
*/
} }
} }