in java/src/main/java/org/apache/brooklyn/rest/client/BrooklynApi.java [408:421]
public static <T> T getEntity(Response response, GenericType<T> type) {
if (response instanceof ClientResponse) {
ClientResponse<?> clientResponse = (ClientResponse<?>) response;
return clientResponse.getEntity(type);
} else if (response instanceof BuiltResponse) {
// Handle BuiltResponsePreservingError turning objects into Strings
if (response.getEntity() instanceof String) {
failSomeErrors(response, type.getType(), true);
return new Gson().fromJson(response.getEntity().toString(), type.getGenericType());
}
}
// Last-gasp attempt.
return type.getType().cast(response.getEntity());
}