从 Solr 查询中获取 application/json

Getting application/json back from a Solr query

我正在使用 Jersey 客户端调用 Solr REST api:

final ClientResponse resp =
  client().path(queryPath())
          .queryParam("q", query.getQuery())
          .queryParam("wt", "json")
          .accept(MediaType.APPLICATION_JSON_TYPE)
          .get(ClientResponse.class);

resp.getEntity(HttpResponse.class)

当我 运行 它时,我得到:

A message body reader for Java class challenger.HttpResponse, and Java type class challenger.HttpResponse, and MIME media type text/plain; charset=UTF-8 was not found

这向我表明响应是 'text/plain' 而不是请求的 'application/json'。

是否有可能从 solr get 查询中获得真正的 JSON 响应,或者我是否需要自己将作为文本返回的 JSON 编组到对象中?

wt 参数应根据 this 处理 JSON 响应格式。然而,有时事情可能会出错,如 JSON 响应可以作为纯文本返回,并在 solrconfig.xml 中进行更改。也请检查该选项。希望这可以帮助您确定问题。