Returning list of process instances when a rest endpoint is invoked

Hi there,

I am trying to do something very basic, I have autowired runtimeService and wrote a simple endpoint like this -
public List sayHello(@PathVariable String hello) {
return runtimeService.createProcessInstanceQuery().list();

but when I invoke this, I get below error -
[org.springframework.http.converter.HttpMessageNotWritableException: Could not write JSON: (was java.lang.NullPointerException); nested exception is com.fasterxml.jackson.databind.JsonMappingException: (was java.lang.NullPointerException) (through reference chain: java.util.ArrayList[0]->org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity[“processDefinition”])]

I tried searching and found this has to do with not being able to convert the return value to json and I tried the number of solutions suggested but no luck.

Please could someone advise what exactly I can change to get this working.


Build your own Return object based on the search result, for example a ProcessInstanceDto with id, name, … as attributes. The entity itself is not suited for REST transport.
If you need the complete information, just use the existing camunda REST endpoint, they solved that problem already.

@Pramod_Yadav You need to convert ProcessInstance entity to ProcessInstanceDTO .

For this you need below camunda-rest dependency in the classpath.

    <version>7.15.0</version> <!-- use compatible version as per matrix -->

Try like this below:

private RuntimeService runtimeService;

public List<ProcessInstanceDto> getProcessInstances(int firstResult, int maxResults) {
    List<ProcessInstance> processInstances = runtimeService.createProcessInstanceQuery().active()
            .listPage(firstResult, maxResults);
    List<ProcessInstanceDto> processInstanceDtos = new ArrayList<>(processInstances.size());
            processInstance -> processInstanceDtos.add(ProcessInstanceDto.fromProcessInstance(processInstance)));
    return processInstanceDtos;

thanks for the awesome information.

Thanks for your kind help Arvind and jangalinski…cheers