retrofit: Response.body() is null when http code is 2xx

Should we change GsonResponseBodyConverter’s convert method like this

@Override
public T convert(ResponseBody value) throws IOException {
    JsonReader jsonReader = gson.newJsonReader(value.charStream());
    try {
        T result = adapter.read(jsonReader);
        // if response type is List and it's empty, response json should be "[]"
        if (result == null && type != Void.class) {
            throw new RuntimeException("response cannot be null");
        }
        return result;
    } finally {
        value.close();
    }
}

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 16 (8 by maintainers)

Most upvoted comments

@GitAyan please create a new issue with an executable test case that reproduces the problem.