RESTEasy client: reconstructing an object

社会主义新天地 提交于 2019-12-19 21:48:48

问题


I'm playing with RESTEasy to consume REST services, and I'm trying it out with Twitter's search API.

So I create this interface:

public interface SimpleClient {

  @GET
  @Path("search.json")
  @Produces("application/json")
  ClientResponse<Set<String>> getSearchResults(
      @QueryParam("q") String hashtag, 
      @QueryParam("result_type") String resultType
  );
}

and called it with:

SimpleClient client = 
    ProxyFactory.create(SimpleClient.class,"http://search.twitter.com/");
ClientResponse<Set<String>> response = 
    client.getSearchResults("#wowodc","recent");
System.out.println(response.getEntity(Set.class));

But I'm getting:

ClientResponseFailure: Unable to find a MessageBodyReader of content-type application/json;charset="utf-8" and type interface java.util.Set

I have tried using a POJO instead of java.util.Set, but I'm getting the same kind of exception. The only thing that didn't throw an exception is using String instead of Set.

By reading some example code on the Web, I was thinking that Set or a POJO as the entity type would have work, but it doesn't for me. The query to Twitter did return valid results.


回答1:


You need to make sure you include a RESTEasy provider that can unmarshal JSON responses. There's a one based on the Jackson parser library that you can use, it's described in the docs here.



来源:https://stackoverflow.com/questions/6004660/resteasy-client-reconstructing-an-object

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!