我想得到:List<User>
。我有端点(GET)来获取用户。得到:
[
{
"id": "d71dcbca-54f3-4b19-aec4-3776bfe34730",
"name": "test",
"surname": "test",
"login": "test",
"password": "-26104458",
"email": "test",
"role": "user"
}
]
我尝试使用rest模板获取此列表:
ResponseEntity<User[]> responseEntity = rest.getForEntity(my-endpoint, User[].class);
return Arrays.asList(responseEntity.getBody());
但我得到这个错误:
org.springframework.web.client.RestClientException: Could not extract response: no suitable HttpMessageConverter found for response type
问题:如何使用其他模板获取List<User>
?
答案 0 :(得分:1)
也许你想尝试这种方法:
ResponseEntity<List<User>> responseEntity = rest.exchange(
"your-endpoint",
HttpMethod.GET,
null,
new ParameterizedTypeReference<List<User>>() {
});