我正在使用 CXF 来创建宁静的服务。其中一项服务返回一个字符串列表。当列表中有多个项目时,CXF 返回一个字符串数组,但当我只有一个元素时,它返回字符串而不是带有 json 的数组:
对于一件物品:
{"ImageResponse":{"images":"hello"}}
有两个项目:
{"ImageResponse":{"images":["hello","hi"]}}
有没有办法始终返回列表,即使列表只有一项?
我的响应类:
@XmlRootElement
public class ImageResponse {
private List<String> images;
//getter and setter
}
尝试在您的 cxf json 提供程序上将 'serializeAsArray' 设置为 true。参考 :http://cxf.apache.org/docs/jax-rs-data-bindings.html http://cxf.apache.org/docs/jax-rs-data-bindings.html
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)