in genie-client/src/main/java/com/netflix/genie/client/GenieClientUtils.java [145:178]
static <T> List<T> parseSearchResultsResponse(
final Response<JsonNode> response,
final String searchResultKey,
final Class<T> clazz
) throws IOException {
if (!response.isSuccessful()) {
throw new GenieClientException(
"Search failed due to "
+ (response.errorBody() == null ? response.message() : response.errorBody().toString())
);
}
// Request returned some 2xx
final JsonNode body = response.body();
if (body == null || body.getNodeType() != JsonNodeType.OBJECT) {
return Lists.newArrayList();
}
final JsonNode embedded = body.get("_embedded");
if (embedded == null || embedded.getNodeType() != JsonNodeType.OBJECT) {
// Kind of an invalid response? Could return error or just swallow?
return Lists.newArrayList();
}
final JsonNode searchResultsJson = embedded.get(searchResultKey);
if (searchResultsJson == null || searchResultsJson.getNodeType() != JsonNodeType.ARRAY) {
return Lists.newArrayList();
}
final List<T> searchList = new ArrayList<>();
for (final JsonNode searchResultJson : searchResultsJson) {
final T searchResult = GenieClientUtils.treeToValue(searchResultJson, clazz);
searchList.add(searchResult);
}
return searchList;
}