[英]RestTemplate.postForObject and Lists
Hi i want a client to consume a restfull webservice.嗨,我想要一个客户端使用一个完整的 web 服务。 I use springboot and the service return a JSON list with just ONE OBJECT.我使用 springboot,服务返回一个 JSON 列表,其中只有一个 OBJECT。 I want to use postForObject Api of RestTemplate like this我想像这样使用 RestTemplate 的 postForObject Api
ResponseEntity<List<RetrieveRichiestaResponseDto>> result = restTemplate.postForObject(
uri,
entity,
new ParameterizedTypeReference<List<RetrieveRichiestaResponseDto>>() {});
Why it gives me this error为什么它给我这个错误
> The method postForObject(String, Object, Class<T>, Object...) in the
> type RestTemplate is not applicable for the arguments (String,
> HttpEntity<capture#3-of ?>, new
> ParameterizedTypeReference<List<RetrieveRichiestaResponseDto>>(){})
Thx for help!谢谢帮助!
restTemplate.postForObject()
don't support ParameterizedTypeReference<>
restTemplate.postForObject()
不支持ParameterizedTypeReference<>
Use restTemplate.exchange()
使用restTemplate.exchange()
ResponseEntity<List<RetrieveRichiestaResponseDto>> result = restTemplate.exchange(uri, HttpMethod.POST, entity,
new ParameterizedTypeReference<List<RetrieveRichiestaResponseDto>>() {});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.