本文介绍了无法找到内容类型application / json的MessageBodyReader并输入类java.lang.String的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用带有jackson提供商的RestEasy客户端并收到上述错误

I am using RestEasy client with jackson providers and getting the above error

客户端代码为:

ClientRequest request = new ClientRequest(url);
request.accept(MediaType.APPLICATION_JSON);
ClientResponse<String> response = request.get(String.class);

if (response.getStatus() != 200) {
  throw new RuntimeException("Failed : HTTP error code : " + response.getStatus());
}

BufferedReader br =
  new BufferedReader(new InputStreamReader(new ByteArrayInputStream(response.getEntity().getBytes())));

response.getEntity()投掷 ClientResponseFailure 异常,错误是

Unable to find a MessageBodyReader of content-type application/json and type class java.lang.String

我的服务器端代码如下:

My server side code is below:

@GET
@Path("/{itemId}")
@Produces(MediaType.APPLICATION_JSON)
public String item(@PathParam("itemId") String itemId) {
  //custom code

  return gson.toJSON(object);
}


推荐答案

您可以尝试添加以下依赖于你的maven pom。

You could try to add the following dependency to your maven pom.

   <dependency>
    <groupId>org.jboss.resteasy</groupId>
    <artifactId>resteasy-jackson-provider</artifactId>
    <version>2.3.4.Final</version>
   </dependency>

这篇关于无法找到内容类型application / json的MessageBodyReader并输入类java.lang.String的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-27 12:25
查看更多