UnmarshalException:在springboot中的对象中捕获xml rest Web服务响应时出现意外元素

问题描述

问题: 造成原因:javax.xml.bind.UnmarshalException:意外元素(uri:“ http://www.original.com/webapp-response”,本地:“ response”)。期望的元素是

通过SOAP UI进行的其他Web服务xml响应:

<response status="ok" xsi:schemaLocation="http://www.original.com/webapp-response http://schemas.original.com/releases/11.3/webapp-response.xsd" xmlns="http://www.original.com/webapp-response" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <eventResponse>
      <transactionList>
         <transaction>
            <id>1234567</id>
         </transaction>
         <transaction>
            <id>1324567</id>
         </transaction>
         <transaction>
            <id>1432567</id>
         </transaction>
         <transaction>
            <id>1523467</id>
         </transaction>
      </transactionList>
   </eventResponse>
</response>

创建的ResponseBean是:

@SuppressWarnings("PMD")
@XmlRootElement(name="transactionList")
@XmlAccessorType(XmlAccesstype.FIELD)
public class TransactionResponse {

    @XmlElement(name="transactionList")
    private List<Transaction> transactionList;

    public List<Transaction> getTransactionList() {
        return transactionList;
    }
    public void setTransactionList(List<Transaction> transactionList) {
        this.transactionList = transactionList;
    }
}

@XmlAccessorType(XmlAccesstype.FIELD)
public class Transaction {
    
    @XmlAttribute(name = "id")
    private String id;
    public String getId() {
        return id;
    }
    public void setId(String id) {
        this.id = id;
    }
}

通过rest模板交换方法捕获对象响应的Java代码

    HttpHeaders requestHeaders = new HttpHeaders();
    Map<String,String> params = new HashMap<String,String>();
    
    params.put("action","Transactions");
    params.put("startDate","14092020 00:00:00");
    params.put("endDate","14092020 23:59:59");
            
    requestHeaders.add("Accept",MediaType.APPLICATION_JSON_VALUE);
    requestHeaders.add("Cookie",strSession);
    httpentity<Object> entity = new httpentity<>(requestHeaders);
                    
    ResponseEntity<TransactionResponse> response = null;
    restTemplate = new RestTemplate();
    response = restTemplate.exchange(eoLoginURL,HttpMethod.POST,entity,TransactionResponse.class,params);

有人可以指出是什么根本原因或缺少什么吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)