无法找到内容类型为 application/json 且类型为 java.lang.String 的 MessageBodyReader [英] Unable to find a MessageBodyReader of content-type application/json and type class java.lang.String

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

问题描述

我正在使用带有 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 异常,错误为

response.getEntity() is throwing ClientResponseFailure exception with the error being

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 且类型为 java.lang.String 的 MessageBodyReader的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆