cancel
Showing results for 
Search instead for 
Did you mean: 

CustomObjectType not storing value

jorell
Champ in-the-making
Champ in-the-making
I have created a custom object type for lists (ArrayList). I set these types in the process engine config as follows:

VariableType listType = new CustomObjectType("list", List.class);
List<VariableType> customVariableTypeLists = Lists.newArrayList(listType);
processEngineConfigurationImpl.setCustomPreVariableTypes(customVariableTypeLists);


When I set a variable of this type, it the type gets stored correctly but the value is empty. I traced as far back as VariableInstanceEntity.create(String name, VariableType type, Object value) method. The name and type get set correctly. The ArrayList Object also gets stored as the cachedValue. But the database doesnt have the value and when try to get the variable from the execution its null (I do see the variable with the correct name in the execution's variable list).

Is there something special I need to do here. I couldnt find any documentation on this in the user guide or the forum so I had no sample to follow.
Thanks for your help.
3 REPLIES 3

martin_grofcik
Confirmed Champ
Confirmed Champ
Hi,

May be you can follow item and message from ProcessEngineConfigurationImpl (activiti sources).

      variableTypes.addType(new CustomObjectType("item", ItemInstance.class));
      variableTypes.addType(new CustomObjectType("message", MessageInstance.class));

Regards
Martin

jorell
Champ in-the-making
Champ in-the-making
Thanks Martin. I think I was doing something similar to the Item and Message Types but maybe I missed something. Before I saw your message though I think I solved it by adding ListVariableType class which extends activiti's SerializableType:

<code>
import org.activiti.engine.impl.variable.SerializableType;

import java.util.ArrayList;
import java.util.List;

public class ListVariableType extends SerializableType {

  @Override
  public String getTypeName() {
    return "list";
  }

  @Override
  public boolean isAbleToStore(Object value) {
    return value instanceof List || value instanceof ArrayList;
  }

}
</code>


I then changed my process engine config setup to be:

<code>
VariableType listType = new ListVariableType();
List<VariableType> customVariableTypeLists = Lists.newArrayList(listType);
processEngineConfigurationImpl.setCustomPreVariableTypes(customVariableTypeLists);
</code>

So far this seems to work. Please let me know if you think there are any problems with this approach.

frederikherema1
Star Contributor
Star Contributor
Seems to be a valid approach, thanks for sharing