RestTemplate.postForObject和列表

问题描述 投票:0回答:1

您好,我希望客户端使用Restfull Web服务。我使用springboot,该服务仅返回一个对象就返回一个JSON列表。我想像这样使用RestTemplate的postForObject Api

ResponseEntity<List<RetrieveRichiestaResponseDto>> result = restTemplate.postForObject(
                uri,
                entity,
                new ParameterizedTypeReference<List<RetrieveRichiestaResponseDto>>() {});

为什么会给我这个错误

> 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>>(){})

感谢您的帮助!

spring-boot rest web-services resttemplate
1个回答
0
投票

[restTemplate.postForObject()不支持ParameterizedTypeReference<>

使用restTemplate.exchange()

ResponseEntity<List<RetrieveRichiestaResponseDto>> result = restTemplate.exchange(uri, HttpMethod.POST, entity, 
       new ParameterizedTypeReference<List<RetrieveRichiestaResponseDto>>() {}).getBody();
© www.soinside.com 2019 - 2024. All rights reserved.