Am fetching documents from Elasticsearch via ActiveMQ using @Controller
. Am calling my client method with parameter and getting response from Elastic Search as JSONArray but while am returning JSONArray from my @Controller
class am getting the below error
Please find my error below.
com.fasterxml.jackson.databind.exc.InvalidDefinitionException: No serializer found for class org.json.JSONObject and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS)
at com.fasterxml.jackson.databind.exc.InvalidDefinitionException.from(InvalidDefinitionException.java:77) ~[jackson-databind-2.9.5.jar:2.9.5]
at com.fasterxml.jackson.databind.SerializerProvider.reportBadDefinition(SerializerProvider.java:1191) ~[jackson-databind-2.9.5.jar:2.9.5]
at com.fasterxml.jackson.databind.DatabindContext.reportBadDefinition(DatabindContext.java:312) ~[jackson-databind-2.9.5.jar:2.9.5]
at com.fasterxml.jackson.databind.ser.impl.UnknownSerializer.failForEmpty(UnknownSerializer.java:71) ~[jackson-databind-2.9.5.jar:2.9.5]
Please find my @Controller
class and my @ResponseBody method
@Controller
public class SearchProductWebService {
private static final String DOCUMENTS = "/document/{name}";
private static final Logger logger = Logger.getLogger(SearchProductWebService.class.getName());
com.demo.earchengineclient.Client searchEngineClient = com.demo.searchengineclient.Client.getInstance();
@RequestMapping(value = DOCUMENTS, method = RequestMethod.GET)
public @ResponseBody Object getDocumentByName(HttpServletRequest httpRequest, HttpServletResponse httpResponse, @PathVariable("name") String name) {
System.out.println("Search Documents--->"+searchEngineClient.searchByDocuments("arthi"));
return searchEngineClient.searchByDocuments(name);
}
}
Please find my client code implementation :
public JSONArray searchByDocuments(String name) {
JSONObject request = new JSONObject();
request.put("method", "search_by_documents");
request.put("name", name);
this.start();
JSONObject response = producer.post(request, 60);
this.stop();
return response.getJSONArray("result");
}