我正在尝试为其中一个 API 编写集成测试,但它返回一个 XML 对象,其中我没有任何相应的类来映射。没有上课怎么办?
这是我的代码
HttpHeaders authHeaders = new HttpHeaders();
authHeaders.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
authHeaders.add("Authorization", "Bearer "+oAuthToken );
UriComponentsBuilder builder=UriComponentsBuilder.fromUriString(PES_END_POINT + PES_RESOURCE)
.queryParam("count", "100")
.queryParam("app-name", "bb")
HttpEntity entity = new HttpEntity(authHeaders);
Object response = restTemplate.exchange(builder.toUriString(), HttpMethod.POST, entity , Class<T> ); --> Here what generic class can I provide?
任何帮助将不胜感激。
只需使用 ObjectMapper
ResponseEntity<String> response = restTemplate.exchange(builder.toUriString(), HttpMethod.POST, entity , String.class);
JavaType javaType = objectMapper.getTypeFactory().constructType(yourClass);
YourGenericClass<T> result = objectMapper.readValue(response.getBody(), javaType);