Map<String, List<Map<String, Object>>> singleMap = (Map<String, List<Map<String, Object>>>) json.apply(from);
List<Map<String, Object>> result = singleMap.get("policies");
ImmutableList.Builder<ScalingPolicyResponse> scalingPoliciesList = ImmutableList.builder();
for(Map<String, Object> scalingPolicyMap : result) {
ScalingPolicyTargetType targetType = null;
for(String key : scalingPolicyMap.keySet()) {
if(ScalingPolicyTargetType.getByValue(key).isPresent()) {
targetType = ScalingPolicyTargetType.getByValue(key).get();
break;
}
}
ImmutableList.Builder<Link> links = ImmutableList.builder();
for(Map<String, String> linkMap : (List<Map<String, String>>) scalingPolicyMap.get("links")) {
Link link = Link.builder().href(URI.create(linkMap.get("href"))).relation(Relation.fromValue(linkMap.get("rel"))).build();
links.add(link);
}
Double d = (Double)scalingPolicyMap.get(targetType.toString()); // GSON only knows double now
ScalingPolicyResponse scalingPolicyResponse =
new ScalingPolicyResponse(
(String)scalingPolicyMap.get("name"),
ScalingPolicyType.getByValue((String)scalingPolicyMap.get("type")).get(),
((Double)scalingPolicyMap.get("cooldown")).intValue(),