in java/src/main/java/org/apache/brooklyn/rest/client/BrooklynApi.java [348:364]
public static <T> T getEntity(Response response, Class<T> type) {
if (response instanceof ClientResponse) {
ClientResponse<?> clientResponse = (ClientResponse<?>) response;
return clientResponse.getEntity(type);
}
Object entity = response.getEntity();
// Handle JSON BuiltResponsePreservingError turning objects into Strings
if (entity instanceof String && !type.isAssignableFrom(String.class)) {
failSomeErrors(response, type, true);
return new Gson().fromJson(response.getEntity().toString(), type);
}
// Last-gasp attempt.
return type.cast(response.getEntity());
}