2013-11-20 97 views
1

在Activiti中,所有複雜對象都使用Java序列化進行序列化並存儲在數據庫中。我希望爲我的自定義類型覆蓋此行爲並將對象存儲爲JSON。這應該有助於我更好地控制持久對象。Activiti自定義變量類型問題

我已經創建了我的自定義VariableType來執行此操作。下面是摘錄

public class CustomVariableType extends ByteArrayType{ 
// overrided all the needed method. 
} 

這些類型的Activiti的配置IMPL如下配置:

public class WorklistConfigurationService { 

    private ProcessEngineConfigurationImpl processEngineConfigurationImpl; 
    private List<CustomVariableType> customVarsTypes; 
    public void init(){ 
     logger.debug("inside init"); 
     for(VOVariableType varType : voVars){ 
      logger.debug("adding type {}", varType.getTypeName()); 
      processEngineConfigurationImpl.getVariableTypes().addType(varType, 0); 
     } 
    } 
    // getter and setters... 
} 

下面是怎麼了注射值高於春季

<bean id="processEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration"> 
     <property name="dataSource" ref="dataSource" /> 
    </bean> 
    <bean id="worklistConfigurationService" 
     class="...WorklistConfigurationService" init-method="init"> 
     <property name="customVarTypes"> 
      <list> 
       <bean id="var1" class="...CustomVariableType"> 
        <constructor-arg type="java.lang.String" value="custom" /> 
        <constructor-arg type="java.lang.Class" 
         value="..CustomType" /> 
       </bean> 
      </list> 
     </property> 
     <property name="processEngineConfigurationImpl" ref="processEngineConfiguration" /> 
    </bean> 

但新序列化機制從未被activiti引擎使用過。相反,它總是使用默認的序列化。有人可以幫助解決這個問題。

+0

你是否也覆蓋'CustomVariableType'中的'isAbleToStore'方法?什麼是voVar? – matts

+0

@matts我只是想隱藏我的商業類名稱。將voVars重命名爲自定義類型。是的,我重寫了isAbleToStore方法。 – ajjain

+0

我不知道如何,但同一段代碼工作。我的不好,有人可以關閉這個問題。順便說一句,我打算分享這個GIST,這樣可以參考。這是記錄最少但非常有用的功能之一。一旦完成GIST,就會在這裏更新。主持人請lemme知道如果共享代碼鏈接是不允許的。 – ajjain

回答

1

我終於得到了問題的根源。在下面DeserializedObject類代碼

public class DeserializedObject { 

    Object deserializedObject; 
    byte[] originalBytes; 
    VariableInstanceEntity variableInstanceEntity; 

    public DeserializedObject(Object deserializedObject, byte[] serializedBytes, VariableInstanceEntity variableInstanceEntity) { 
    this.deserializedObject = deserializedObject; 
    this.originalBytes = serializedBytes; 
    this.variableInstanceEntity = variableInstanceEntity; 
    } 

    public void flush() { 
    // this first check verifies if the variable value was not overwritten with another object 
    if (deserializedObject==variableInstanceEntity.getCachedValue() && !variableInstanceEntity.isDeleted()) { 
     byte[] bytes = VOVariableType.serialize(deserializedObject, variableInstanceEntity); 
     if (!Arrays.equals(originalBytes, bytes)) { 
     variableInstanceEntity.setBytes(bytes); 
     } 
    } 
    } 
} 

此行是問題的原因:

byte[] bytes = SerializableType.serialize(deserializedObject, variableInstanceEntity); 

代碼總是使用SerializableType序列化對象。序列化默認爲默認序列化。並有一個問題...

我不知道現在如何進一步移動。

+0

我也在討論這個@activiti論壇。請按照這裏的對話http://forums.activiti.org/content/custom-serialization-complex-process-variable – ajjain