Single element array bug in XStream

Viewed 103

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 Answers

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

Related