• Register
0 votes
3.1k views

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>)
6 5 3
7,540 points

Please log in or register to answer this question.

1 Answer

0 votes

Solution :

I was also having the very similar problem, and it turned out to be the very simple; my client was not including the Jackson dependency, even though my code all compiled correctly, but the auto-magic converters for the JSON were not being included in it.

To summarize, I just added a Jackson dependency to my pom.xml and it just worked as follows :

<dependency>
<groupId>com.fasterxml.jackson.core</groupId><artifactId>jackson-databind</artifactId><version>2.5.1</version>
</dependency>
9 7 4
38,600 points

Related questions

0 votes
1 answer 86 views
86 views
Problem: could anybody help me to fix this ? Could not extract response: no suitable httpmessageconverter found for response type.
asked Mar 6 Wafa Abu Yousef 6.1k points
1 vote
1 answer 16 views
16 views
Problem : What does this mean > @Autowired - No qualifying bean of type found for dependency
asked Apr 23 Abik Dey 4k points
0 votes
1 answer 43 views
43 views
Problem: I need help in solving this error: Could not obtain transaction-synchronized session for current thread.
asked Mar 13 Wafa Abu Yousef 6.1k points
1 vote
1 answer 2.6K views
2.6K views
Problem : I am beginner to spring + hibernate. Recently I have created the application with the use of spring + hibernate but I always face below error. I am trying to work on it for the very first time. Below is the error for your ... ) at coreservlets.StudentDAOImpl.create(StudentDAOImpl.java:19) at coreservlets.MainApp.main(MainApp.java:14) Can somebody help me in overcoming above error?
asked Mar 28, 2020 morrisBson 3.2k points
1 vote
1 answer 4 views
4 views
Problem: Need a solution : Nosuchbeandefinitionexception: no qualifying bean of type.
asked Apr 29 PkGuy 23.5k points
0 votes
2 answers 315 views
315 views
Problem : I have created entities, services and JUnit tests for services using Spring and Hibernate for my project. All of these are working. After that I added spring-mvc to it to make this web application but while trying to make ... follows ..Could not autowire field: public pl.com.radzikowski.webmail.service.IMailManager pl.com.radzikowski.webmail.controller.HomeController.mailManager...
asked Nov 20, 2019 peterlaw 6.9k points
1 vote
1 answer 3 views
3 views
Problem: Any clue to this? Java.lang.illegalstateexception: response has already been committed.
asked May 2 PkGuy 23.5k points
0 votes
1 answer 12 views
12 views
Problem: Is anyone available to assist me and resolve this issue? java.lang.illegalstateexception: cannot call senderror() after the response has been committed
asked Apr 7 Ifra 37.2k points
0 votes
1 answer 3 views
3 views
Problem: What is wrong here? >Content type 'multipart/form-data boundary=' not supported
asked 3 days ago Chi Omega 13.6k points
0 votes
1 answer 78 views
78 views
Problem : I am trying to write Spring boot code The Program is running but I am getting following error: This application has no explicit mapping for /error, so you are seeing this as a fallback. How to fix this error?
asked Mar 6 Wafa Abu Yousef 6.1k points