Getting application/json back from a Solr query

747 views Asked by At

I'm calling the Solr REST api using a Jersey client:

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)

and when I run it I get:

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

Which suggests to me that the response is 'text/plain' rather than the 'application/json' requested.

Is it possible to get a real JSON response from a solr get query or do I need to marshal the JSON returned as text into an object myself?

1

There are 1 answers

1
Ramzy On BEST ANSWER

The wt param, should take care of JSON response format, as per this. However, things can go wrong sometimes, as mentioned like JSON responses can be returned as plain text, with a change in solrconfig.xml. Please check that option also. Hope this helps you in identifying the issue.