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
Solved! Go 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
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
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
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
Thank you- This worked like a charm!
Ask for and offer help to other Alfresco Process Services and Activiti Users and members of the Alfresco team.
By using this site, you are agreeing to allow us to collect and use cookies as outlined in Alfresco’s Cookie Statement and Terms of Use (and you have a legitimate interest in Alfresco and our products, authorizing us to contact you in such methods). If you are not ok with these terms, please do not use this website.