I have seen the answers of many other posts, but would like to understand if there is a better way to do the same.
Requirement: - I use restTemplate to talk to a web service that returns JSON output, which is dynamic. As a consumer, I do not want to access all the fields, but I am interested in a few of them. I use Spring framework with Jackson parser and found a way to access it
String response = restTemplate.getForObject(targetUrl, String.class);
System.out.println(response);
ObjectMapper mapper = new ObjectMapper();
JsonNode rootNode = mapper.readValue(response, JsonNode.class);
JsonNode uri = rootNode.get("uri");
System.out.println(uri.asText());
Do you know the best way to do this? Mapping to java Object is what I don't want to do, as json output is not in my control
source
share