I have a requirement where I need to fetch the response of various company results. Each company will share a REST API with me (with all the details to invoke the API). I need to read a particular param from the response. The param will be known to me in advance and it might differ for every API.
Since the response for all the APIs will be different, I am looking for a generic method of calling the URL (always GET) and parsing the response in a JSON format and read the output param.
I tried doing the following:
String response = restTemplate.getForObject(URL,request,String.class);
But this fails to invoke the API. I also tried doing:
Object response = restTemplate.getForObject(URL,request,Object.class);
and
JsonNode response = restTemplate.getForObject(URL,request,JsonNode.class);
This also doesn’t work. Is there any other way so that I can invoke the API and convert its response in a JSON object and read a particular property of the JSON.
I am not an expert but is this feasible in Java (I have done something similar with JS, but ofcourse it has much relaxed datatypes).
Thanks for any inputs.