Cannot work with serializers outside of command context

I am trying to set the process variable in a non Java Delegate class, which is called from a Camunda Java delegate class, and in the non java delegate class, I am trying to set the process variable:

          delegateExecution
              .setVariable(PubSubConstant.ENTITY_TYPE_ID, eventConfiguration.getEntityTypeId().toString());
          delegateExecution.setVariable(PubSubConstant.CONFIG_RECORD,
              mapper.writeValueAsString(eventConfiguration));
          delegateExecution.setVariable(PubSubConstant.EVENT_RECORD, eventRecord.value());

I am getting the following error:

    org.camunda.bpm.engine.ProcessEngineException: ENGINE-03041 Cannot work with serializers outside of command context.
	at org.camunda.bpm.engine.impl.db.EnginePersistenceLogger.serializerOutOfContextException(EnginePersistenceLogger.java:392)
	at org.camunda.bpm.engine.impl.persistence.entity.util.TypedValueField.getSerializers(TypedValueField.java:234)
	at org.camunda.bpm.engine.impl.persistence.entity.util.TypedValueField.setValue(TypedValueField.java:132)
	at org.camunda.bpm.engine.impl.persistence.entity.VariableInstanceEntity.<init>(VariableInstanceEntity.java:131)
	at org.camunda.bpm.engine.impl.persistence.entity.VariableInstanceEntity.create(VariableInstanceEntity.java:150)
	at org.camunda.bpm.engine.impl.persistence.entity.VariableInstanceEntityFactory.build(VariableInstanceEntityFactory.java:31)
	at org.camunda.bpm.engine.impl.persistence.entity.VariableInstanceEntityFactory.build(VariableInstanceEntityFactory.java:25)
	at org.camunda.bpm.engine.impl.core.variable.scope.AbstractVariableScope.setVariableLocal(AbstractVariableScope.java:340)
	at org.camunda.bpm.engine.impl.core.variable.scope.AbstractVariableScope.setVariable(AbstractVariableScope.java:307)
	at org.camunda.bpm.engine.impl.core.variable.scope.AbstractVariableScope.setVariable(AbstractVariableScope.java:288)
	at com.hitachi.vantara.mieventhandling.services.EventProcessHandler.recordArrived(EventProcessHandler.java:79)
	at com.hitachi.vantara.mieventhandling.services.EventConfigurationThreads.run(EventConfigurationThreads.java:77)
	at java.base/java.lang.Thread.run(Thread.java:834)
1 Like