Несовместимое ограничение равенства Java: список <MyRequest>и список <MyResponse> - PullRequest
0 голосов
/ 14 декабря 2018
public class RestClient {    

        public <T> ResponseEntity<T> Execute(String url, HttpMethod method, HttpEntity<T> entity, ParameterizedTypeReference<T> parameterizedTypeReference) throws KeyStoreException, NoSuchAlgorithmException, KeyManagementException {

            TrustStrategy acceptingTrustStrategy = (X509Certificate[] chain, String authType) -> true;

            SSLContext sslContext = org.apache.http.ssl.SSLContexts.custom()
                    .loadTrustMaterial(null, acceptingTrustStrategy)
                    .build();

            SSLConnectionSocketFactory csf = new SSLConnectionSocketFactory(sslContext);

            CloseableHttpClient httpClient = HttpClients.custom()
                    .setSSLSocketFactory(csf)
                    .build();

            HttpComponentsClientHttpRequestFactory requestFactory =
                    new HttpComponentsClientHttpRequestFactory();

            requestFactory.setHttpClient(httpClient);
            RestTemplate restTemplate = new RestTemplate(requestFactory);

            return restTemplate.exchange(url, method, entity, parameterizedTypeReference);

        }
    }

public class APISerive {

    private RestClient client;

    public List<MyResponse > CreateContacts(List<MyRequest> createContactDetailsRequestDTOS) {

    ResponseEntity<List<MyResponse>> result =
                 client.Execute("apiurl", HttpMethod.POST, entity, new ParameterizedTypeReference<List<MyResponse>>() {});

    return result;

    }
}

Для приведенного выше кода я создал универсальный клиент отдыха, который вызывает внешний API, но я получаю сообщение об ошибке в строке ниже

client.Execute("apiurl", HttpMethod.POST, entity, new ParameterizedTypeReference<List<MyResponse>>() {})

Ошибки:

org.springframework.http.HttpEntity для сущности (org ... MyRequest >>)

org ... core.ParameterizedTypeReference для сущности new ... MyResponse >> ({} (анонимно ... MyResponse)>>)

для 3-го и 4-го аргумента метода Execute ()

...