Search code examples
javajsonspring-bootalfrescoactiviti

SpringBoot - activiti - Get the active task List


I would like to get the active Tasks List , using:

return processEngine.getTaskService().createTaskQuery().active().list();

but I have this error:

10:05:37.238 [http-nio-1061-exec-18] ERROR e.e.e.o.k.f.c.s.ControllerAdvice - Could not write JSON: lazy loading outside command context; nested exception is com.fasterxml.jackson.databind.JsonMappingException: lazy loading outside command context (through reference chain: java.util.ArrayList[0]->org.activiti.engine.impl.persistence.entity.TaskEntityImpl["variableInstances"])

Solution

  • You tried to call the service and returned the List directly, instead use a List<Map<String, Object>>. See the below code snippet which can help you,

    public List<Map<String, Object>> getTaskList() {
    List<Tasks> taskList = gprocessEngine.getTaskService().createTaskQuery().active().list();
    
        List<Map<String, Object>> customTaskList = new ArrayList<>();
            for (Task task : taskList) {
                Map<String, Object> map = new LinkedHashMap<>();
                map.put("taskId", task.getId());
                map.put("taskDefinitionKey", task.getTaskDefinitionKey());
                map.put("taskName", task.getName());
        
                customTaskList.add(map);
            }
            return customTaskList;