Problem :
I am trying to use the curl command as follows:
curl -u 591bf65f50057469f10b5fd9:0cf17f9b03d056ds0e11e48497e506a2 https://backend.tdk.com/api/devicetypes/59147fd79e93s12e61499ffe/messages
But I am getting a JSON response as follows:
{"data":[{"device":"18SE62","time":1494516023,"data":"3235","snr":"36.72",...
I have saved the response on the txt file and parse it using jackson, and everything is fine as below:
ObjectMapper mymapper = new ObjectMapper();
File myfile = new File(getClass().getResource("/result.json").getFile());
MessageList mymessageList = mymapper.readValue(myfile, MessageList.class);
Also I am assuming that I should get the same result using the RestTemplate but that's not the case as below:
RestTemplate myrestTemplate = new RestTemplate();
MessageList mymessageList =
myrestTemplate.getForObject("http://592693f43c87815f9b8145e9:f099c85d84d4e325a2186c02bd0caeef@backend.tdk.com/api/devicetypes/591570373c87894b4eece34d/messages", MessageList.class);
But I got an error instead as below:
Exception in thread "main" org.springframework.web.client.RestClientException: Could not extract response: no suitable HttpMessageConverter found for response type [class com.tdk.domain.backend.MessageList] and content type [text/html;charset=iso-8859-1]
at org.springframework.web.client.HttpMessageConverterExtractor.extractData(HttpMessageConverterExtractor.java:88)
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:711)
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:520)
at org.springframework.web.client.RestTemplate.getForObject(RestTemplate.java:114)
at com.tdk.controllers.restful.client.RestTemplateExample.main(RestTemplateExample.java:14)
I also tried to set the contentType as follows:
HttpHeaders myheaders = new HttpHeaders();
myheaders.setContentType(MediaType.APPLICATION_JSON);
HttpEntity<String> myentity = new HttpEntity<String>("parameters", myheaders);
MessageList mymessageList = myrestTemplate.getForObject(myurl, myentity, MessageList.class);
however then I got a compilation error as below
The method getForObject(String, Class<T>, Object...) in the type RestTemplate is not applicable for the arguments (String, HttpEntity<String>,Class<MessageList>)