06-16-2017 02:25 PM
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 issuejava.lang.ClassCastException: com.activiti.model.common.AbstractRepresentationSystem.out.println("The size is: " +list.get(0)); // Prints size 1TaskRepresentation t = list.get(0); // Throws below exception 😞
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
06-21-2017 04:27 PM
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
06-20-2017 07:51 AM
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
06-20-2017 11:30 AM
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
06-21-2017 04:27 PM
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
10-25-2018 10:08 AM
Thank you- This worked like a charm!
Explore our Alfresco products with the links below. Use labels to filter content by product module.