Search code examples
springcamundabpmnbusiness-process-managementcamunda-modeler

How to get user task List with assignee userId in camunda with java api?


I want to get user tasklist with java api in my service or controller layer with: taskService.createTaskQuery().taskAssignee(userId) for Camunda Engine; and my code:

@GetMapping("/user-tasklist={userId}")
@ResponseBody
public List<Task> userTaskList(@PathVariable String userId){

    return taskService.createTaskQuery().taskAssignee(userId).list();

}

And i get the error :Context.getCommandContext()" is null!!! What is "CommandContext()" and how do I solve this problem? Am I using the wrong method? Such a method was used in the documentation and code samples, but I did not see anything about "CommandContext()" and it seems that this method works, but not for me.

Error:

2022-12-29 00:37:44.263 WARN 17664 --- [nio-8081-exec-2] .w.s.m.s.DefaultHandlerExceptionResolver : Resolved [org.springframework.http.converter.HttpMessageNotWritableException: Could not write JSON: Cannot invoke "org.camunda.bpm.engine.impl.interceptor.CommandContext.getExecutionManager()" because the return value of "org.camunda.bpm.engine.impl.context.Context.getCommandContext()" is null; nested exception is com.fasterxml.jackson.databind.JsonMappingException: Cannot invoke "org.camunda.bpm.engine.impl.interceptor.CommandContext.getExecutionManager()" because the return value of "org.camunda.bpm.engine.impl.context.Context.getCommandContext()" is null (through reference chain: java.util.ArrayList[0]->org.camunda.bpm.engine.impl.persistence.entity.TaskEntity["execution"])]


Solution

  • You are returning the Task directly from the camunda java API. This Taskis just an interface, implemented by the inner logic of a TaskEntity in camunda. It is not serializable via json.

    You need to map the task in the controller function to some kind of TaskDto that can be serialized.

    You can write your own custom dto, use the default camunda REST API Task based on the OpenAPI spec (example here) or use (my) immutables project:

    ImmutableTask dto = CamundaImmutables.task(task)