對應(yīng)用戶自己定義的非string類型的變量,jBPM是先將變量轉(zhuǎn)換成二進(jìn)制object 流,然后再轉(zhuǎn)換成string類型存儲(chǔ)在數(shù)據(jù)庫中,取變量的過程與之相反。由于轉(zhuǎn)換成string涉及到編碼格式問題,如GBK、ISO等,而編碼格式涉及到操作系統(tǒng)、數(shù)據(jù)庫、jvm等多方面的影響,jbpm目前還沒有解決這個(gè)問題,因此在使用非string類型變量的時(shí)候,jbpm會(huì)出錯(cuò)。這個(gè)問題tom(jbpm創(chuàng)始人)正在解決。
這個(gè)問題,似乎將變量按二進(jìn)制存儲(chǔ)更好些,這樣就不會(huì)涉及編碼格式問題。
另外一種方法是使用統(tǒng)一的編碼格式,改寫后的org.jbpm.delegation.serializerSerializableSerializer如下:
public class SerializableSerializer implements Serializer {
public String serialize(Object object) {
String serialized = null;
if (object != null) {
if (!(object instanceof Serializable)) {
throw new IllegalArgumentException("object ‘" + object + "‘ (" +
object.getClass().getName() +
") cannot be serialized with " +
this.getClass().getName());
}
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(object);
oos.flush();
baos.flush();
serialized = baos.toString(“ISO-8859-1“);//修改
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException(
"couldn‘t serialize state definition");
}
}
return serialized;
}
public Object deserialize(String text) {
Object object = null;
if (text != null) {
try {
ByteArrayInputStream bais = new ByteArrayInputStream(text.
getBytes(“ISO-8859-1“)); //修改
ObjectInputStream ois = new ObjectInputStream(bais);
object = ois.readObject();
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(
"couldn‘t deserialize object from inputstream");
}
}
return object;
}
}
聯(lián)系客服