如果您具有这样的功能:
List<User> getUsers() {}
如果getUsers返回List仅包含一个元素的,则生成的JSON只是JSON对象,而不是JSON数组。
List
是否有使XStream返回JSON数组的变通办法,而不管该函数是否返回单个数组List?
解决方案是降级到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