由于 JAX-WS 依赖于 JAXB,并且由于我在 JAX-B 参考实现中观察到了解压 XML bean 的代码,因此我猜想并没有什么区别,并且 JAXWS 客户端总是返回一个空集合,即使 Web 服务结果是空元素:
public T startPacking(BeanT bean, Accessor<BeanT, T> acc) throws AccessorException {
T collection = acc.get(bean);
if(collection==null) {
collection = ClassFactory.create(implClass);
if(!acc.isAdapted())
acc.set(bean,collection);
}
collection.clear();
return collection;
}
我同意,为了获得最佳的互操作性,服务契约应该是明确的并避免此类差异,但似乎我正在调用的 JAX-WS 服务(托管在具有 Jbossws 实现的 Jboss 服务器上)总是按预期返回 null 空集合(使用 SoapUI 进行测试)。
我使用 wsimport 生成的测试代码。
返回元素定义为:
@XmlElement(name = "return", nillable = true)
protected List<String> _return;
我什至测试了更改 Response 类 getReturn 方法:
public List<String> getReturn() {
if (_return == null) {
_return = new ArrayList<String>();
}
return this._return;
}
to
public List<String> getReturn() {
return this._return;
}
但没有成功。
欢迎任何有关此问题的有用信息/评论!