我的问题是,如果我调用这个 URL 并得到一个字符串的响应,我得到了它,但是没有 Class ESearchResult。我在这里做错了什么?请帮忙...
String url = "https://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?db=pubmed&term=covid";//config.getPmcUrl() + "esearch.fcgi?db=pubmed&term=covid";
RestTemplate restTemplate = this.getRestTemplate();
HttpHeaders headers = this.getHeaders();
HttpEntity<ESearchResult> requestEntity = new HttpEntity<ESearchResult>(headers);
//ResponseEntity<ESearchResult> response = restTemplate.exchange(url, HttpMethod.GET, requestEntity, ESearchResult.class);
ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.GET, requestEntity, String.class);
String esearch = response.getBody(); //this works
//ESearchResult esearch = response.getBody();//this doesn't work
ESearchResult 类我检查是否有命名空间。
@Getter
@Setter
@XmlAccessorType(value = XmlAccessType.FIELD)
@XmlRootElement(name = "eSearchResult", namespace = "http://eutils.ncbi.nlm.nih.gov/eutils/dtd/20060628/esearch.dtd")
public class ESearchResult {
/*@XmlElement(name = "IdList", namespace = "https://eutils.ncbi.nlm.nih.gov/eutils/dtd/20060628/esearch.dtd")
private List<IdList> idList;*/
@XmlElement(name = "Count", namespace = "https://eutils.ncbi.nlm.nih.gov/eutils/dtd/20060628/esearch.dtd")
private Integer count;
@XmlElement(name = "RetMax", namespace = "https://eutils.ncbi.nlm.nih.gov/eutils/dtd/20060628/esearch.dtd")
private Integer retMax;
@XmlElement(name = "RetStart", namespace = "https://eutils.ncbi.nlm.nih.gov/eutils/dtd/20060628/esearch.dtd")
private Integer retStart;
}
来自 URL 的结果