XStream中的单元素数组错误 [英] Single element array bug in XStream

查看:173
本文介绍了XStream中的单元素数组错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果您具有这样的功能:

If you have a function like this:

List<User> getUsers() {}

如果getUsers返回仅包含一个元素的List,则生成的JSON只是JSON对象,而不是JSON数组.

If getUsers returns a List with just one element the resulting JSON is just a JSON Object rather than a JSON array.

是否存在使XStream返回JSON数组的变通办法,而不管该函数是否返回单个数组List?

Is there a workaround to make XStream return JSON array regardless if the function returns single array List?

推荐答案

解决方案是降级到Jettison 1.2

The solution is to downgrade to Jettison 1.2

    <dependency>
        <groupId>org.restlet.jee</groupId>
        <artifactId>org.restlet.ext.xstream</artifactId>
        <version>${version.restlet}</version>
        <exclusions>
            <exclusion>
                <groupId>org.codehaus.jettison</groupId>
                <artifactId>jettison</artifactId>
            </exclusion>
            <exclusion>
                <groupId>com.thoughtworks.xstream</groupId>
                <artifactId>xstream</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.restlet.jee</groupId>
        <artifactId>org.restlet.ext.json</artifactId>
        <version>${version.restlet}</version>
    </dependency>
    <dependency>
        <groupId>org.codehaus.jettison</groupId>
        <artifactId>jettison</artifactId>
        <version>1.2</version>
    </dependency>
    <dependency>
        <groupId>com.thoughtworks.xstream</groupId>
        <artifactId>xstream</artifactId>
        <version>1.4.11.1</version>
    </dependency>

根据XStream数组错误 https://github.com/jettison-json/jettison/issues/12

As per XStream array bug https://github.com/jettison-json/jettison/issues/12

这篇关于XStream中的单元素数组错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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