Здравствуйте, я столкнулся с проблемой при использовании RestTemplate для отправки запросов к другому приложению в моей архитектуре микросервисов. Когда я пытаюсь получить данные с помощью RestTemplate, я получаю следующую ошибку:
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 =
public Integer getDurationWithContentId(Long id)
throws Exception {
URL url = discoveryServiceHandler.buildApiUrl("vod-client","/content/" + id + "/duration");
return restTemplate.getForObject(url.toURI(), Integer.class);
}
контроллер приложения, которое я запрашиваю =
@GetMapping("/{id}/duration")
public ResponseEntity 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;
}
}
Я пытался получить ответ как объект, но получаю эту ошибку =
java.lang.RuntimeException: Unexpected response format: {=84}
я тоже пытался сделать такой запрос, но тоже не могу получить ответ
ResponseEntity response = restTemplate.exchange(url.toURI(), HttpMethod.GET, null, new ParameterizedTypeReference() {});
Подробнее здесь: https://stackoverflow.com/questions/784 ... eger-error