javajacksonflowable

Flowable: Jackson transformation Deployment of flowable, prompt CommandContextUtil. GetResourceEntityManager () is null


This is my call

public IPage<Deployment> deploymentPage(Query query, String key, String name, String tenantId) {
    DeploymentQuery deploymentQuery = repositoryService.createDeploymentQuery();
    if (StringUtil.isNotBlank(key)) {
        deploymentQuery.deploymentKeyLike(StringPool.PERCENT + key + StringPool.PERCENT);
    }
    if (StringUtil.isNotBlank(name)) {
        deploymentQuery.deploymentNameLike(StringPool.PERCENT + name + StringPool.PERCENT);
    }
    if (StringUtil.isNotBlank(tenantId)) {
        deploymentQuery.deploymentTenantId(tenantId);
    }
    IPage<Deployment> page = Condition.getPage(query);
    long count = deploymentQuery.count();
    List<Deployment> deployments = deploymentQuery.orderByTenantId().orderByDeploymentTime().desc().listPage((query.getCurrent() - 1) * query.getSize(), query.getSize());
    page.setRecords(deployments);
    page.setTotal(count);
    return page;
}

I use JSON to return IPage\<Deployment\>

Error:

Could not write JSON: (was java.lang.NullPointerException); nested exception is com.fasterxml.jackson.databind.JsonMappingException: (was java.lang.NullPointerException) (through reference chain: org.springblade.core.tool.api.R["data"]->com.baomidou.mybatisplus.extension.plugins.pagination.Page["records"]->java.util.ArrayList[0]->org.flowable.engine.impl.persistence.entity.DeploymentEntityImpl["resources"])

After locating, it was found that CommandContextUtil.getResourceEntityManager().findResourcesByDeploymentId(id); line CommandContextUtil.getResourceEntityManager() is null

    @Override
    public Map<String, EngineResource> getResources() {
        if (resources == null && id != null) {
            List<ResourceEntity> resourcesList = CommandContextUtil.getResourceEntityManager().findResourcesByDeploymentId(id);
            resources = new HashMap<>();
            for (ResourceEntity resource : resourcesList) {
                resources.put(resource.getName(), resource);
            }
        }
        return resources;
    }

Solution

  • The public Java API classes from Flowable, such as Deployment, are not build to be returned directly over REST. If you want to return them, you'll need to create your own DTOs to achieve what you want to achieve.