Array or JSON Object Process Variable

It seems the engine is not allowing me to save arrays and json objects to the process using execution.setVariable

Doing the following results in an error:

var t = [5, 6];
execution.setVariable(“values”, t);

Hi,

the exception says:

org.flowable.engine.common.api.FlowableException: couldn't find a variable type that is able to serialize [object Array]
	at org.flowable.engine.impl.variable.DefaultVariableTypes.findVariableType(DefaultVariableTypes.java:62)
	at org.flowable.engine.impl.persistence.entity.VariableScopeImpl.createVariableInstance(VariableScopeImpl.java:863)
	at org.flowable.engine.impl.persistence.entity.ExecutionEntityImpl.createVariableInstance(ExecutionEntityImpl.java:531)
	at org.flowable.engine.impl.persistence.entity.VariableScopeImpl.createVariableLocal(VariableScopeImpl.java:784)
	at org.flowable.engine.impl.persistence.entity.VariableScopeImpl.setVariable(VariableScopeImpl.java:662)
	at org.flowable.engine.impl.persistence.entity.VariableScopeImpl.setVariable(VariableScopeImpl.java:654)

You can easily add new type support in ProcessEngineConfiguration.
See org.flowable.engine.impl.cfg.ProcessEngineConfigurationImpl#initVariableTypes

public void initVariableTypes() {
    if (variableTypes == null) {
        variableTypes = new DefaultVariableTypes();
        if (customPreVariableTypes != null) {
            for (VariableType customVariableType : customPreVariableTypes) {
                variableTypes.addType(customVariableType);
            }
        }
        variableTypes.addType(new NullType());
        variableTypes.addType(new StringType(getMaxLengthString()));
        variableTypes.addType(new LongStringType(getMaxLengthString() + 1));

The example in the jUnit test is org.flowable.examples.variables.VariablesTest#testBasicVariableOperations

Regards
Martin

Hi Martin,

What is the method for doing this in flowable 6. ProcessEngineConfiguration does not have any methods for setting variable types.

Regards

Brian

Got it to work by injecting my type into config. See below. Is there a reason that there is no method on the ProcessEngineConfiguration interface. Not sure why I needed to use the Impl class:

ProcessEngineConfiguration cfg = new StandaloneProcessEngineConfiguration()
.setJdbcUrl(“jdbc:h2:mem:flowable;DB_CLOSE_DELAY=-1”)
.setJdbcUsername(“sa”)
.setJdbcPassword("")
.setJdbcDriver(“org.h2.Driver”)
.setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE);

	//cfg.getDef	
		
  ProcessEngineConfigurationImpl processEngineConfig = (ProcessEngineConfigurationImpl)cfg;
  processEngineConfig.initVariableTypes();
  processEngineConfig.getVariableTypes().addType(new CustomObjectType("camelbody", CamelBody.class));

  ProcessEngine processEngine =  processEngineConfig.buildProcessEngine();

@boneill you If you use an instance of the StandaloneProcessEngineConfiguration then you would get access to it. On top of that I would advise against doing what you are doing? calling initVariableTypes and then adding to it.

Instead I would do:

ProcessEngineConfiguration cfg = new StandaloneProcessEngineConfiguration()
.setJdbcUrl(“jdbc:h2:mem:flowable;DB_CLOSE_DELAY=-1”)
.setJdbcUsername(“sa”)
.setJdbcPassword("")
.setJdbcDriver(“org.h2.Driver”)
.setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE)
.setCustomPostVariableTypes(Arrays.asList(new CustomObjectType("camelbody", CamelBody.class)));

ProcessEngine processEngine =  processEngineConfig.buildProcessEngine();

Cheers,
Filip