Camunda Task object to JSON

We use Spring Boot embedded Camunda Engine and implement our own TaskList UI which makes call to our API to get list of active tasks.

Inside our API, we use Camunda Engine API to retrieve list of active tasks as below,
List<Task> tasks = processEngine.getTaskService().createTaskQuery().active().list()

However Camunda Task object cannot be serialized to JSON.

Is there a way we can pass the Task objects as JSON to our TaskList UI? We do not use Camunda Restful API.

@hanscrg , You need to convert Task object to TaskDTO.

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>
</dependency>

Try like this below:

@Autowired
private TaskService taskService;

public List<TaskDto> getTaskList(String processDefinitionKey) {
		
   List<Task> taskList = taskService.createTaskQuery()
                   .processDefinitionKey(processDefinitionKey).active().list();

   List<TaskDto> taskDtoList = new ArrayList<>();
  
   taskList.forEach(taskInstance -> {
	  TaskDto taskDto = TaskDto.fromEntity(taskInstance);
	  taskDtoList.add(taskDto);
    });

   return taskDtoList;

}
4 Likes