I am trying to return solr response in JSON format. However I am not able to get the JSON response. Below is my solr config:'
<queryResponseWriter name="json" default="true" class="org.apache.solr.request.JSONResponseWriter">
<str name="content-type">application/json</str>
</queryResponseWriter>
Below is my java code:
HttpSolrServer server = new HttpSolrServer(serverUrl);
SolrQuery query = new SolrQuery();
query.setQuery(query);
query.set("indent","true");
query.set("wt","json");
QueryResponse response = server.query(query);
System.out.println(response.getResults().get(index));
However output is displyed in following format.
{numFound=1,start=0,docs=[SolrDocument{_uniqueKey=[“abc@gmail.com”,”abc”], calculation_policy=text_value, username=abc, email=abc@gmail.com, display_order=10, last_login=Mon Jan 26 11:27:35 PST 2015, created=Mon Jan 26 11:27:35 PST 2015}]}
However I get JSON response after execute following line:
System.out.println(new Gson().toJson(queryResponse.getResults().get(index)));
Can someone please tell me what step am I missing?