* @param json the JSON that should represent a location
*
* @return the location
*/
private Location buildLocationFromJSON(JSONObject json) {
LocationBuilder builder = new LocationBuilder();
Set<String> iso3166Codes = new HashSet<>();
Map<String, Object> metadata = new HashMap<>();
if (json.containsKey("iso3166Codes")) {
for (Object rawCode : json.getJSONArray("iso3166Codes")) {
iso3166Codes.add((String)rawCode);
}
}
if (json.containsKey("metadata")) {
JSONObject rawMetadata = json.getJSONObject("metadata");
for (Object rawKey : rawMetadata.keySet()) {
metadata.put((String)rawKey, rawMetadata.get(rawKey));
}
}
builder.description(json.containsKey("description") ? json.getString("description") : null)
.iso3166Codes(iso3166Codes)
.id(json.containsKey("id") ? json.getString("id") : null)
.scope(json.containsKey("scope") ? LocationScope.valueOf(json.getString("scope")) : null)
.metadata(metadata);
return builder.build();
}