我正在使用RESTEasy来使用REST服务,而我正在尝试使用Twitter的搜索API。
所以我创建了这个界面:
public interface SimpleClient {
@GET
@Path("search.json")
@Produces("application/json")
ClientResponse<Set<String>> getSearchResults(
@QueryParam("q") String hashtag,
@QueryParam("result_type") String resultType
);
}
并用:
调用它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));
但我得到了:
ClientResponseFailure:无法找到内容类型application / json的MessageBodyReader; charset =“utf-8”并输入interface java.util.Set
我尝试使用POJO而不是java.util.Set,但我得到了同样的异常。唯一没有抛出异常的是使用String而不是Set。
通过阅读Web上的一些示例代码,我认为Set或POJO作为实体类型可以工作,但它不适合我。对Twitter的查询确实返回了有效结果。