I’m trying to get all the process definitions in my Database with a simple call List<ProcessDefinition> processDefinitionList = repositoryService.createProcessDefinitionQuery().list();
and try to serialize it. The problem is that I receive the following error:
Could not write JSON: (was java.lang.NullPointerException); nested exception is -> java.util.ArrayList[0]->org.flowable.engine.impl.persistence.entity.ProcessDefinitionEntityImpl["identityLinks"]
I think there’s something wrong with data in the DB, like dirty info, so I’ve tried cleaning some tables in the DB, I’ve tried truncating cascade some act_ru and act_id but I think there something else to do, I just don’t want to mess up with the DB. How can I solve this?
Hey @TodoMary,
You should not be serializing the ProcessDefinition
directly to JSON. You should create your own DTOs and map the definition into those or use the ProcessDefinitionResponse
from flowable-rest
. You can also use the RestResponseFactory
from flowable-rest
that has methods to map from ProcessDefinition
into ProcessDefinitionResponse
.
Cheers,
Filip
1 Like
Thank you @filiphr, can I ask why in particular is better to do like this and not serialize it? What is the reason behind this?
The reason is that the ProcessDefinitionEntityImpl
(which is the implementation of `ProcessDefinition) is not designed for direct serialization. Jackson uses reflection to perform the serialization, so it will serialize things that are not in the interface.
Also in general it is never good to serialize interfaces where you don’t know the actual implementation, usually over REST you want to have a defined API and what it would be returned. Therefore, defining your own DTO or using the ProcessDefinitionResponse
is the way to go (in my opinion).
1 Like