SpringBoot-activiti-获取活动任务列表

SpringBoot - activiti - Get the active task List

我想获取活动任务列表,使用:

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

但是我有这个错误:

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"])

您尝试调用服务并直接返回列表,而不是使用 List<Map<String, Object>>。请参阅下面的代码片段,它可以帮助你,

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;