Spring RestTemplate получить доступ к сайту DEMO не удается: не удалось извлечь ответ: не найдено подходящего HttpMessageConverter - PullRequest
0 голосов
/ 14 февраля 2020

Почему этот простой запрос RestTemplate на DEMO-сайт http://dummy.restapiexample.com/api/v1/employee/ не выполняется?

В, например, Postman запрос в порядке.

ResponseEntity<ExternalEmployeeRequest> responseEntity;
try {
    String url = "http://dummy.restapiexample.com/api/v1/employee/11;
    responseEntity = restTemplate.getForEntity(url, ExternalEmployeeRequest.class);
    if ( ! HttpStatus.OK.equals( responseEntity.getStatusCode())) {
        LOGGER.error("Employee with id {} with httpstatus {}", employeeId, responseEntity.getStatusCode().toString());
    }
} catch (Exception e) {
    LOGGER.error("Employee with id {} with message {}", employeeId, e.getMessage());
    return null;
}

Я получаю это сообщение:

Сотрудник с идентификатором 11 с сообщением Не удалось извлечь ответ: не найден подходящий HttpMessageConverter для типа ответа [class ndsmodel.ExternalEmployeeRequest] и типа содержимого [text / html; charset = UTF-8]

Классы:

public class ExternalEmployeeRequest {
    private String status;
    private ExternalEmployee data;

    public ExternalEmployeeRequest() {
    }
    // Getters and setters
}

И

public class ExternalEmployee {
    private int id;
    private String employeeName;
    private double employeeSalary;
    private int employeeAge;
    private String image;

    public ExternalEmployee() {
    }

    // Getters and setters
}
...