CopyPastor

Detecting plagiarism made easy.

Score: 0.8008646965026855; Reported for: String similarity Open both answers

Possible Plagiarism

Plagiarized on 2021-09-25
by Faramarz Afzali

Original Post

Original - Posted on 2017-05-27
by Ilya Dyoshin



            
Present in both answers; Present only in the new answer; Present only in the old answer;

I guess there is a solution for this exception. Try out and let me know the result. Not any message converter can read your HTTP response, so it fails with an exception. The main problem here is a **content-type**, In order to overcome this, you can introduce a custom message converter. and register it for all kinds of responses (i.e. ignore the response content-type header). Just like this
```java List<HttpMessageConverter<?>> messageConverters = new ArrayList<HttpMessageConverter<?>>(); MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
// We are making this converter to process any kind of response, not only application/*json, which is the default behaviour converter.setSupportedMediaTypes(Collections.singletonList(MediaType.ALL)); messageConverters.add(converter); restTemplate.setMessageConverters(messageConverters); ```
The main problem here is **content type [text/html;charset=iso-8859-1]** received from the service, however the real content type should be **application/json;charset=iso-8859-1**
In order to overcome this you can introduce custom message converter. and register it for all kind of responses (i.e. ignore the response content type header). Just like this
List<HttpMessageConverter<?>> messageConverters = new ArrayList<HttpMessageConverter<?>>(); //Add the Jackson Message converter MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
// Note: here we are making this converter to process any kind of response, // not only application/*json, which is the default behaviour converter.setSupportedMediaTypes(Collections.singletonList(MediaType.ALL)); messageConverters.add(converter); restTemplate.setMessageConverters(messageConverters);



        
Present in both answers; Present only in the new answer; Present only in the old answer;