aashi
June 20, 2019, 5:17am
1
Hello,
I’m trying to set a variable to process instance like,
Map<String, Object> variables = new HashMap<String, Object)
variables.put(“process”, process);
ProcessInstance flowableProcessInstance = runtimeService.
startProcessInstanceByKey(“CAS_Process”);
Error: couldn’t find a variable type that is able to serialize
Here process is an xml model and for this issue I found Array or JSON Object Process Variable but can you explain how setCustomPostVariableTypes works and how can I use it in my scenario?
Regards,
Ashmita Sinha
Hi Aashi,
Can’t you make your XML model as serializable? if you make model serializable flowable will implicitly handle them saving to DB.
Thanks,
Hi Ashmita,
customPostVariableTypes work exactly in the same way as standard types. They are added to variableTypes during initialization.
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));
variableTypes.addType(new BooleanType());
variableTypes.addType(new ShortType());
variableTypes.addType(new IntegerType());
variableTypes.addType(new LongType());
variableTypes.addType(new DateType());
variableTypes.addType(new JodaDateType());
variableTypes.addType(new JodaDateTimeType());
variableTypes.addType(new DoubleType());
variableTypes.addType(new UUIDType());
variableTypes.addType(new JsonType(getMaxLengthString(), objectMapper));
variableTypes.addType(new LongJsonType(getMaxLengthString() + 1, objectMapper));
variableTypes.addType(new ByteArrayType());
variableTypes.addType(new SerializableType(serializableVariableTypeTrackDeserializedObjects));
if (customPostVariableTypes != null) {
for (VariableType customVariableType : customPostVariableTypes) {
variableTypes.addType(customVariableType);
}
}
}
}
You can add your own implementation of SerializableType to the customPostVariableTypes. As an example have a look on flowable-engine/modules/flowable-variable-service/src/main/java/org/flowable/variable/service/impl/types/LongStringType.java at b12ac2d23c176f8b35aeef4aa6c4bee8b3610bad · flowable/flowable-engine · GitHub
In your scenario there are many possibilities but If you want to implement your own SerializableType for Process class. Just do that and add it to customPostVariableTypes.
Regards
Martin