Hello i am encountering an issue while using RestTemplate to make requests to another application in my microservices architecture. When I try to fetch data using RestTemplate, I receive the following error:
Error while extracting response for type [class java.lang.Integer] and content type [application/xml;charset=UTF-8]; nested exception is org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Cannot deserialize instance of `java.lang.Integer` out of START_OBJECT token; nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of `java.lang.Integer` out of START_OBJECT token
Rest Template Request =
public Integer getDurationWithContentId(Long id) throws Exception { URL url = discoveryServiceHandler.buildApiUrl("vod-client","/content/" + id +"/duration"); return restTemplate.getForObject(url.toURI(), Integer.class); }
controller of the application I request =
@GetMapping("/{id}/duration") public ResponseEntity<Integer> getRawVideoDuration(@PathVariable Long id) throws IOException { log.info(LogGenerator.enter()); try { return new ResponseEntity<>(contentService.getRawMediaDuration(id), HttpStatus.OK); } catch (Exception e) { log.error("Error in getRawVideoDuration: {}", e.getMessage()); throw e; } }
I tried to get response as a object but i get this error =
java.lang.RuntimeException: Unexpected response format: {=84}
also i tried to request like that but i can't get response either
ResponseEntity<Integer> response = restTemplate.exchange(url.toURI(), HttpMethod.GET, null, new ParameterizedTypeReference<Integer>() {});