当列表只有一个元素时,CXF返回对象,而不是js数组 [英] When a list has only one element, CXF return the object instead a js array

查看:160
本文介绍了当列表只有一个元素时,CXF返回对象,而不是js数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用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屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆