我的问题是:jax-ws 如何生成与@XmlJavaTypeAdapter 关联的解组代码?我在客户端代码中看不到适配器类(而是将它们分解为它们的适应对象)。因此,当调用 Web 服务方法时,客户端如何知道如何解组返回的封送响应?
细节:
我在另一个 @XmlJavaTypeAdapter 注释中使用 @XmlJavaTypeAdapter 注释,以便将 Map<> 转换为 ArrayList。编组的结果很好。我的 jax-ws 生成的客户端似乎无法解组结果。相反,我只得到一个空对象。
这是发送到客户端的 XML:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<dlwmin:getRefTableResponse xmlns:dlwmin="http://service.web.test/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<wsRefDataObject>
<map>
<entry>
<key>05</key>
<value>
<columns>
<entry>
<key>state</key>
<value>CA</value>
</entry>
<entry>
<key>code</key>
<value>05</value>
</entry>
</columns>
</value>
</entry>
</map>
</wsRefDataObject>
</dlwmin:getRefTableResponse>
这是我的 WsRefDataOject 适配器类:
我对 ReferenceDataEntry 解组代码(地图对象)使用相同的逻辑。
public class MyMapAdapter extends XmlAdapter<MyMapType, Map<String,ReferenceDataEntry>> {
public MyMapType marshal(Map<String,ReferenceDataEntry> bt) throws Exception {
MyMapType myMapType = new MyMapType();
for(Map.Entry<String,ReferenceDataEntry> entry : bt.entrySet()) {
MyMapEntryType myMapEntryType = new MyMapEntryType();
myMapEntryType.key = entry.getKey();
myMapEntryType.value = entry.getValue();
myMapType.entry.add(myMapEntryType);
}
return myMapType;
}
public Map<String, ReferenceDataEntry> unmarshal(MyMapType v) throws Exception {
Map<String, ReferenceDataEntry> map = new HashMap<String, ReferenceDataEntry>();
for(MyMapEntryType myEntryType : v.entry){
map.put(myEntryType.key, myEntryType.value);
}
return map;
}
}
我可以在编组代码中设置断点并在服务中单步执行;但是,我不确定何时/何地存储/调用解组代码。适配器类不是在客户端生成的,所以我不确定客户端应该如何知道如何解组返回的 xml。
下面是生成的 WsRefDataObject 类和生成的 ReferenceDataEntry 类:
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "wsRefDataObject", namespace = "http://service.web.test/", propOrder = {
"map"})
public class WsRefDataObject {
protected MyMapType map;
/**
* Gets the value of the map property.
*
* @return
* possible object is
* {@link MyMapType }
*
*/
public MyMapType getMap() {
return map;
}
/**
* Sets the value of the map property.
*
* @param value
* allowed object is
* {@link MyMapType }
*
*/
public void setMap(MyMapType value) {
this.map = value;
}}
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "referenceDataEntry", namespace = "http://service.web.test/", propOrder = {
"columns"})
public class ReferenceDataEntry {
protected RefMapType columns;
/**
* Gets the value of the columns property.
*
* @return
* possible object is
* {@link RefMapType }
*
*/
public RefMapType getColumns() {
return columns;
}
/**
* Sets the value of the columns property.
*
* @param value
* allowed object is
* {@link RefMapType }
*
*/
public void setColumns(RefMapType value) {
this.columns = value;
}}
关于导致客户端中的空对象的任何想法?