简体   繁体   中英

RESTEasy client: reconstructing an object

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.

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM