jBPM的type问题,big bug!

       对应用户自己定义的非string类型的变量,jBPM是先将变量转换成二进制object 流,然后再转换成string类型存储在数据库中,取变量的过程与之相反。由于转换成string涉及到编码格式问题,如GBK、ISO等,而编码格式涉及到操作系统、数据库、jvm等多方面的影响,jbpm目前还没有解决这个问题,因此在使用非string类型变量的时候,jbpm会出错。这个问题tom(jbpm创始人)正在解决。
       这个问题,似乎将变量按二进制存储更好些,这样就不会涉及编码格式问题。
       另外一种方法是使用统一的编码格式,改写后的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;
    }

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 5
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值