当列表只有一个元素时,CXF返回对象,而不是js数组 [英] When a list has only one element, CXF return the object instead a js array
问题描述
我正在使用CXF创建宁静的服务.其中一项服务返回一个字符串列表.当我在列表中有多个项目时,CXF返回一个字符串数组,但是当我只有一个元素时,它返回String而不是一个带有json的数组:
I'm using CXF to create restful services. One of the services return a list of string. When I have more than one item in the list, the CXF returns an array of strings, but when I have only one element, it returns the String instead an array with a json:
有一件物品:
{"ImageResponse":{"images":"hello"}}
有两个项目:
{"ImageResponse":{"images":["hello","hi"]}}
即使列表只有一项,有没有办法总是返回列表?
Is there a way to always return a list, even when the list has only one item?
我的回应班:
@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
Try setting 'serializeAsArray' as true on your cxf json provider. Refer : http://cxf.apache.org/docs/jax-rs-data-bindings.html
这篇关于当列表只有一个元素时,CXF返回对象,而不是js数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!