issues with Custom REST resource

I implemented a custom REST resource using this wiki. And I am having the following error whenever I try the doGetAll and doSearch endpoints.

 {
  "error": {
    "message": "[converting class org.openmrs.module.crudexample.Item to org.openmrs.module.webservices.rest.web.representation.RefRepresentation@269913fc]",
    "code": "org.openmrs.module.webservices.rest.web.ConversionUtil:409",
    "detail": 
}

See the full error here

Here are the methods.

@Override
  protected NeedsPaging<Item> doGetAll(RequestContext context) {
	return new NeedsPaging<Item>(exampleService.getAllItems(), context);
}

@Override
protected PageableResult doSearch(RequestContext context) {
	
	String query = context.getParameter("q");
	
	List<Item> itemsByQuery = null;
	
	if (query != null) {
		itemsByQuery = exampleService.getItems(query, false);
	} else {
		itemsByQuery = exampleService.getAllItems();
	}
	return new NeedsPaging<Item>(itemsByQuery, context);
}

Is your module publicly available such that we take a look at your resouces?

Sure, here.

I find out that this error shows up only when the representation type is set to none, ref, or custom ( that is /resource?v=custom, /resource?v=ref, or just /resource ). So the solution would be to specify the representation to default or full

@redetg i think there are no custom representations defined here , is it the case @dkayiwa?

1 Like