NullPointerException thrown by getIdentityLinks() method of ProcessDefinitionEntityImpl class

Hi, I use repositoryService to retrieve list of process definitions, convert the results to JSON response and return to browser. Here is code snippet:

	@RequestMapping(value = "/rest/process-definitions", method = RequestMethod.GET, produces = "application/json")
	public List<ProcessDefinition> findProcessDefinitions(@RequestParam Map<String, String> allRequestParams) {
		ProcessDefinitionQuery processDefinitionQuery = repositoryService.createProcessDefinitionQuery();
		...
		List<ProcessDefinition> data = processDefinitionQuery.listPage(0, 10);
		return data;
	}

The code above runs normally. However, Spring throws NullPointerException while converting the results to JSON:
org.springframework.http.converter.HttpMessageNotWritableException: Could not write content: (was java.lang.NullPointerException) (through reference chain: java.util.HashMap[“rows”]->java.util.ArrayList[0]->org.flowable.engine.impl.persistence.entity.ProcessDefinitionEntityImpl[“identityLinks”]); nested exception is com.fasterxml.jackson.databind.JsonMappingException: (was java.lang.NullPointerException) (through reference chain: java.util.HashMap[“rows”]->java.util.ArrayList[0]->org.flowable.engine.impl.persistence.entity.ProcessDefinitionEntityImpl[“identityLinks”])

I digged into the source and found that there is getIdentityLinks() method in ProcessDefinitionEntityImpl class, as follows:[code] public List getIdentityLinks() {
if (!isIdentityLinksInitialized) {
definitionIdentityLinkEntities = Context.getCommandContext().getIdentityLinkEntityManager().findIdentityLinksByProcessDefinitionId(id);
isIdentityLinksInitialized = true;
}

    return definitionIdentityLinkEntities;
}

[/code]
Since Context.getCommandContext() returns null here, NullPointerException is thrown.
Question: how could this NullPointerException be avoided? Or if I missed some configuration?
Here is my configuration:[code]


<!-- Checks the version of the flowable DB schema and throws an exception if the versions don’t match -->
<property name="databaseSchemaUpdate" value ="false" />
[/code]

Hi,

It’s best to convert the ProcessDefinitionEntity instances to a custom, simpler Process definition class and return that in your response. The ProcessDefinitionEntity has additional convenience properties that are used for specific cases. And you don’t want these properties to be automatically converted to JSON as you experienced.

Best regards,

Tijs

I see. There are two examples to reference, one is flowable-rest and the other is flowable-ui-task-logic package, which includes the class of ProcessDefinitionRepresentation. Following these examples, one can make a custom response.
Thanks for your reply.