我使用Jersey来构建REST服务并希望返回一个Collection<String>XML.
@GET
@Produces(MediaType.TEXT_XML)
@Path("/directgroups")
public Response getDirectGroupsForUser(@PathParam("userId") String userId) {
try {
Collection<String> result = service.getDirectGroupsForUser(userId, null, true);
// return result; //first try
// return result.toArray(new String[0]); //second try
return Response.ok().type(MediaType.TEXT_XML).entity(result).build(); //third try
} catch (UserServiceException e) {
LOGGER.error(e);
throw new RuntimeException(e.getMessage());
}
}
Run Code Online (Sandbox Code Playgroud)
但我的尝试失败,出现以下异常:
javax.ws.rs.WebApplicationException:com.sun.jersey.api.MessageException:Java类java.util.ArrayList的消息体编写器,Java类型类java.util.ArrayList,MIME媒体类型text/xml不是发现
我发现通过google处理的返回text/json而不是text/xml就像我的情况一样.
谁能帮我?我想,如果我使用Response,那将是我在XML和我的集合中的根元素,其中包含一个字符串元素列表.
我有一个宁静的服务(post)消耗(application/json)并生成(application/json).此服务的单个参数是带注释的java对象.
我正在使用org.jboss.resteasy.client.ClientRequest将请求发送到服务.但是,我在客户端获得此异常并且异常:
找不到内容类型application/json类型的writer.
这是否意味着我缺少一些图书馆罐子,或者我必须为application/json编写自己的编写器?
我正在使用resteasy 2.3.3.Final
以下是我添加到我的pom中的各种依赖项,我认为可能与之相关:
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jaxrs</artifactId>
<version>2.3.3.Final</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.jaxrs</groupId>
<artifactId>jackson-jaxrs-json-provider</artifactId>
<version>2.0.5</version>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jaxb-provider</artifactId>
<version>2.3.4.Final</version>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jackson-provider</artifactId>
<version>2.3.4.Final</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-core-asl</artifactId>
<version>1.3.0</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>1.3.0</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
马特
我有类似于此处描述的情况:动态更改RESTEasy服务返回类型
我面临的问题是我正在尝试返回一个对象列表(带注释@XMLRootEntity),但我得到一个500服务器错误代码:
服务器遇到内部错误(找不到类型的响应对象的MessageBodyWriter:媒体类型的java.util.ArrayList:application/json)阻止它完成此请求.
你能就如何解决这个问题提出一些建议吗?
我不确定在哪里看.
谢谢.