I am doing reverse geocoding using google geocoding API.
The results are returned in Json, which I process as follows -
Map<String, Object> parsedJson = new ObjectMapper().readValue(
response.getEntity(String.class),
new TypeReference<Map<String, Object>>() {
});
List<Object> results = (List<Object>) parsedJson.get("results");
Map<String, Object> geometry = (Map<String, Object>) ((Map<String, Object>) results
.get(0)).get("geometry");
Map<String, Object> location = (Map<String, Object>) geometry
.get("location");
Map<String, Double> coordinates = new HashMap<String, Double>();
coordinates.put("latitude", (Double) location.get("lat"));
coordinates.put("longitude", (Double) location.get("lng"));
Where the response contains Json returned from the server.
Is it possible to get a direct link to a node location without going through all this? For instance. there is something like -
new ObjectMapper().readValue(json).findNodeByName("lat").getFloatValue();
I read the documents in JsonNode and Tree in Jackson Api, but it seems that they are only useful if you want to cross the entire tree.
What would be the easiest way to get only a specific node?
source
share