我有一个 Spring Boot Java 应用程序。我正在使用 spring webservice 模板调用一个肥皂网络服务。webservice 调用总是返回一个 JAXBElement。以下是我的代码片段。
JAXBElement<ItemResponse> itemResponse = (JAXBElement<ItemResponse> ) getWebServiceTemplate().marshalSendAndReceive(
this.cconfServiceConfiguration.getServices().getLocation(), itemRequest,
new SoapActionCallback(this.cconfServiceConfiguration.getServices().getGetItemAction()));
return itemResponse.getValue();
marshalSendAndReceive 返回一个 JAXBElement。有什么办法可以重写代码,以便它返回 ItemResponse 的对象,这样我就可以避免强制转换。以下是 ItemResponse 类声明。
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "ItemResponse", propOrder = {
"result",
"item"
})
public class ItemResponse {
@XmlElement(required = true)
protected Result result;
protected Item item;
/**
* Gets the value of the result property.
*
* @return
* possible object is
* {@link Result }
*
*/
public Result getResult() {
return result;
}
/**
* Sets the value of the result property.
*
* @param value
* allowed object is
* {@link Result }
*
*/
public void setResult(Result value) {
this.result = value;
}
/**
* Gets the value of the item property.
*
* @return
* possible object is
* {@link Item }
*
*/
public Item getItem() {
return item;
}
/**
* Sets the value of the item property.
*
* @param value
* allowed object is
* {@link Item }
*
*/
public void setItem(Item value) {
this.item = value;
}
}
如果你能提供一些信息真的很感激