我正在开发一个桥应用程序,该应用程序将肥皂请求发送到Webservice Restful,并以肥皂形式返回响应。

Restful Webservice的响应是这样的

[
  {
    "agenzia": "string",

    "allegato": [
      {
        "fileName": "string",
        "body": "string",
        "mimeType": "string"
      }
    ]
  }
]


我使用Spring Boot框架进行开发。
我已经从XSD生成了Java文件(保留了“ RetrieveRichiesta”类),然后创建了一个DTO类(“ RetrieveRichiestaResponseDto”类)来处理来自Web服务的响应。
API类是

public RetrieveRichiestaResponse RetrieveRichiesta(RetrieveRichiestaRequest request){
        //LOGGER.info("Servizio richiamato "+ url + "api/incident/retrieveincident");

        // Call the API
        RestTemplate restTemplate = new RestTemplate();
        // Add Interceptor
        restTemplate.setInterceptors(Collections.singletonList(new RequestResponseLoggingInterceptor()) );

        HttpHeaders headers = new HttpHeaders();
        headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
        headers.setContentType(MediaType.APPLICATION_JSON);

        final String uri = url + "/api/incident/retrieveincident";
        Map<String,String> input = new HashMap<>();
        input.put("id_CRM", request.getIdCRM());
        input.put("tipo", request.getTipo());
        input.put("fonte", request.getFonte());

        HttpEntity<?> entity = new HttpEntity<>(input,headers);

        RetrieveRichiestaResponseDto result = restTemplate.postForObject(
                uri,
                entity,
                RetrieveRichiestaResponseDto.class);

        // Transform response RetrieveRichiestaRequestDto to RetrieveRichiestaRequest
        RetrieveRichiesta RetrieveRichiesta = new RetrieveRichiesta();

        RetrieveRichiesta.setAgenzia(result.getAgenzia());

        RetrieveRichiesta.setAllegato(result.getAllegatoDTO());

        RetrieveRichiestaResponse response = new RetrieveRichiestaResponse();
        LOGGER.info("Risposta" + response.toString());

        response.setRetrieveRichiesta(RetrieveRichiesta);

        return response;
    }


当我通过SOAP发送请求时,获得此错误作为响应

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
   <SOAP-ENV:Header/>
   <SOAP-ENV:Body>
      <SOAP-ENV:Fault>
         <faultcode>SOAP-ENV:Server</faultcode>
         <faultstring xml:lang="en">Error while extracting response for type [class eu.ima.app.domain.RetrieveRichiestaDto] and content type [application/json;charset=utf-8]; nested exception is org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Cannot deserialize instance of `eu.ima.app.domain.RetrieveRichiestaDto` out of START_ARRAY token; nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of `eu.ima.app.domain.RetrieveRichiestaDto` out of START_ARRAY token
 at [Source: (PushbackInputStream); line: 1, column: 1]</faultstring>
      </SOAP-ENV:Fault>
   </SOAP-ENV:Body>
</SOAP-ENV:Envelope>


我认为是因为它想要这样的JSON对象{},而不是这样的[{}]

我也尝试过更改这样的代码

......
HttpEntity<?> entity = new HttpEntity<>(input,headers);

        ResponseEntity<List<RetrieveRichiestaResponseDto>> result = restTemplate.exchange(
                uri,
                HttpMethod.POST,
                entity,
                new ParameterizedTypeReference<List<RetrieveRichiestaResponseDto>>() {});
        List<RetrieveRichiestaResponseDto> rates = result.getBody();
        //LOGGER.info(rates.toString());

        for (int i = 0; i < rates.size(); i++) {
            System.out.println(rates.get(i));
        }
......


获得列表,但是如何将其作为列表传递给RetrieveRichiesta?
错误在哪里?
有很多帮助!!

最佳答案

好的,我可以使用

rates.get(0).getAgenzia
Etc.


但是如果我想像这样使用restTemplate.postForObject

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


为什么给我

the method is not applicable for the arguments....


需要帮助请!

10-05 23:27