I have a RestController method which returns
// The method which builds custom JSON response from retrieved data
public List<HashMap<String, Object>> queryTasks() {
return buildResponse(...);
}
In course of time the response became bigger, additional features like search, filtering was required and operating with hashmap become harder. I want to use DTO for this response now, but there was one feature with hashmap:
AbstractProcessEntity parentDomainEntity = domainEntity.getParent();
do {
if (parentDomainEntity != null) {
taskMap.put(parentDomainEntity.getClass().getSimpleName() + "Id", parentDomainEntity.getId()); parentDomainEntity = parentDomainEntity.getParent();
} else {
taskMap.put("parentDomainEntityId", null);
}
} while (parentDomainEntity != null);
JSON response was dynamically build tree for domain entities with not null parents.
Doing it in DTO will lead to creating variable for each parent entity and populating them with null (It's possible to have 5 levels of parent-child entities).
How I can dynamically build response like in my first case with HashMap?