Reputation: 197
I throw when post request via Rest Api, result is
Content-Type: application/json
{
"error": "file content is not in the appropriate format",
"file_name": "15-10-2019-11-19-32_KKK.csv"
}
When I try code on my side, I use the below code
public RestTemplate restTemplateBuilder() {
RestTemplate restTemplate = new RestTemplate(new HttpComponentsClientHttpRequestFactory());
MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
ObjectMapper mapper = new ObjectMapper();
mapper.configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES, true);
converter.setObjectMapper(mapper);
restTemplate.getMessageConverters().add(0, converter);
restTemplate.setErrorHandler(new RestTemplateHandler());
return restTemplate;
}
RestTemplate restTemplate = restTemplateBuilder();
ResponseEntity<FileUploadResponseDTO> serviceResponse = restTemplate.exchange(url, HttpMethod.POST, requestEntity, FileUploadResponseDTO.class);
org.springframework.web.client.RestClientException: Could not extract response: no suitable HttpMessageConverter found for response type [....FileUploadResponseDTO] and content type [text/html] Gives a fault. how do I convert?
Upvotes: 0
Views: 2959
Reputation: 58772
You can add content-type header to RestTemplate:
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
HttpEntity<String> requestEntity = new HttpEntity<String>(headers);
Upvotes: 0