if (!expectedResponseCodes.contains(response.getStatusCode())) {
throw new APIException(request, response);
}
// TODO: once we switch to jackson we can take the media type into account automatically
final MediaType responseContentType;
if (response.getContentType() == null) {
responseContentType = MediaType.JSON_UTF_8;
} else {
responseContentType = MediaType.parse(response.getContentType());
}
if (!responseContentType.is(mediaType.withoutParameters())) {
LOG.warn("We said we'd accept {} but got {} back, let's see how that's going to work out...", mediaType, responseContentType);
}
if (responseClass.equals(String.class)) {
return responseClass.cast(response.getResponseBody("UTF-8"));
}
if (expectedResponseCodes.contains(response.getStatusCode())
|| (response.getStatusCode() >= 200 && response.getStatusCode() < 300)) {
T result;
try {
if (response.getResponseBody().isEmpty()) {
return null;
}
if (responseContentType.is(MediaType.JSON_UTF_8.withoutParameters())) {
result = deserializeJson(response, responseClass);
} else {
LOG.error("Don't know how to deserialize objects with content in {}, expected {}, failing.", responseContentType, mediaType);
throw new APIException(request, response);
}