Hi there,
I am trying to do something very basic, I have autowired runtimeService and wrote a simple endpoint like this -
@GetMapping(“/getInstancesList”)
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.
Thanks
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.
<dependency>
<groupId>org.camunda.bpm</groupId>
<artifactId>camunda-engine-rest-jaxrs2</artifactId>
<version>7.15.0</version> <!-- use compatible version as per matrix -->
</dependency>
Try like this below:
@Autowired
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());
processInstances.forEach(
processInstance -> processInstanceDtos.add(ProcessInstanceDto.fromProcessInstance(processInstance)));
return processInstanceDtos;
}
2 Likes
thanks for the awesome information.
Thanks for your kind help Arvind and jangalinski…cheers