Activiti REST call for list of tasks

cancel
Showing results for 
Search instead for 
Did you mean: 
signjoy
Active Member II

Activiti REST call for list of tasks

Jump to solution

Hello all,

In one requirement we need to fetch data from Alfresco Activiti. We are using RESTTemplate call that returns us list of tasks for the particular user. The only problem is, the response is in JSON format and not showing the type of the corresponding JAVA class. Can anyone tell me that on which java class I need to cast the response?

REST call:  http://localhost:8080/activiti-app/api/enterprise/tasks/query

Restponse:

{
      "size": 1,
      "total": 1,
      "start": 0,
      "data": [
    {
       "id": "42589",
       "name": "Director Review",
       "description": null,
       "category": null,
       "assignee": {
                            "id": 1,
                            "firstName": null,
                            "lastName": "Administrator",
                            "email": "admin@app.activiti.com"
                         },
       "created": "2017-06-15T20:02:26.684+0000",
      "dueDate": null,
      "endDate": null,
       blah...

       blah...
    }
 ]

}

In my JAVA code how and which JAVA object needs to be created like below...

 

ResponseEntity<ResultListDataRepresentation> result =  restTemplate.postForEntity(url, entity, ResultListDataRepresentation .class);
ResultListDataRepresentation rldr = result.getBody();
List<TaskRepresentation> list = (List<TaskRepresentation>) rldr.getData();   // No issue 
System.out.println("The size is: " +list.get(0)); // Prints size 1  
TaskRepresentation t = list.get(0); // Throws below exception :-(
java.lang.ClassCastException: com.activiti.model.common.AbstractRepresentation
cannot be cast to com.activiti.model.runtime.TaskRepresentation

But I need something like to easily manipulate the object.

    List<Task> taskList = restTemplate.postForObject(url, entity, Task.class);

Thanking you

1 Solution

Accepted Solutions
cjose
Senior Member II

Re: Activiti REST call for list of tasks

Jump to solution

Understood, that is because of the way you casting it. 

The "data" field in ResultListDataRepresentation is of type List<? extends AbstractRepresentation>. Hence you get this error as a direct casting to TaskRepresentation will not work.

I have worked out a sample using Jackson lib and see if that helps.

Ciju

View solution in original post

4 Replies
cjose
Senior Member II

Re: Activiti REST call for list of tasks

Jump to solution

Hi,

I'm trying to understand your use case.

Are you trying to the Activiti APIs from a external java application and trying to parse the rest response? JSON is the API response standard in Activiti. If you need to convert the JSON string to a POJO, there are plenty of libraries out there which can help. eg: GitHub - FasterXML/jackson: Main Portal page for Jackson project  

Hope this helps.

Ciju

signjoy
Active Member II

Re: Activiti REST call for list of tasks

Jump to solution

Hey thanks for your reply.

Yes, I am calling Activiti from my java app and getting the JSON. I have Jackson in my project. But I am not sure which POJO I need to create out of the JSON response form activiti.

For example, the above JSON response, I am able to create ResultListDataRepresentation POJO.  It also shows the data size 1. I am not sure to which class I need to cast this list of AbstractRepresentation.  But when I print the data as string on console, it prints the whole JSON with data.

joy

cjose
Senior Member II

Re: Activiti REST call for list of tasks

Jump to solution

Understood, that is because of the way you casting it. 

The "data" field in ResultListDataRepresentation is of type List<? extends AbstractRepresentation>. Hence you get this error as a direct casting to TaskRepresentation will not work.

I have worked out a sample using Jackson lib and see if that helps.

Ciju

paiyyavj13
Established Member II

Re: Activiti REST call for list of tasks

Jump to solution

Thank you- This worked like a charm!