Support primitive string response in Java clients

This commit is contained in:
xhh 2015-09-23 12:49:34 +08:00
parent 69f8274287
commit 44bbe301cb
3 changed files with 21 additions and 4 deletions

View File

@ -385,8 +385,15 @@ public class ApiClient {
if (contentType.startsWith("application/json")) {
return json.deserialize(body, returnType);
} else if (returnType.getType().equals(String.class)) {
// Expecting string, return the raw response body.
return (T) body;
} else {
throw new ApiException(500, "can not deserialize Content-Type: " + contentType);
throw new ApiException(
500,
"Content type \"" + contentType + "\" is not supported for type: "
+ returnType.getType()
);
}
}

View File

@ -389,8 +389,15 @@ public class ApiClient {
if (contentType.startsWith("application/json")) {
return json.deserialize(body, returnType);
} else if (returnType.getType().equals(String.class)) {
// Expecting string, return the raw response body.
return (T) body;
} else {
throw new ApiException(500, "can not deserialize Content-Type: " + contentType);
throw new ApiException(
500,
"Content type \"" + contentType + "\" is not supported for type: "
+ returnType.getType()
);
}
}
@ -429,7 +436,7 @@ public class ApiClient {
}
}
Invocation.Builder invocationBuilder = target.request(contentType).accept(accept);
Invocation.Builder invocationBuilder = target.request().accept(accept);
for (String key : headerParams.keySet()) {
String value = headerParams.get(key);

View File

@ -536,9 +536,12 @@ public class ApiClient {
}
if (contentType.startsWith("application/json")) {
return json.deserialize(respBody, returnType);
} else if (returnType.equals(String.class)) {
// Expecting string, return the raw response body.
return (T) respBody;
} else {
throw new ApiException(
"Content type \"" + contentType + "\" is not supported",
"Content type \"" + contentType + "\" is not supported for type: " + returnType,
response.code(),
response.headers().toMultimap(),
respBody);