Single element array bug in XStream

China☆狼群 提交于 2019-12-02 05:06:46

问题


If you have a function like this:

List<User> getUsers() {}

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

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


回答1:


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>

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



来源:https://stackoverflow.com/questions/52039056/single-element-array-bug-in-xstream

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!