Workaround for the issue that a BigDecimal value becomes 0 using Hessian

1. 现象

  Hessian client调用server端的方法得到一个对象,但其中BigDecimal类型的field值变为0。所用版本为4.0.33。

2. 研究与分析

  通过查询,发现这是hessian的bug,BigDecimal objects are incorrectly serialized,网址是 http://bugs.caucho.com/view.php?id=3920

  竟六年没有修掉这个bug, 目前仍为open状态。

3. 解决办法

  a. 使用上述网页中提到的办法,

adding files

META-INF/hessian/serializers with 'java.math.BigDecimal=com.caucho.hessian.io.StringValueSerializer'

and

META-INF/hessian/deserializers with 'java.math.BigDecimal=com.caucho.hessian.io.BigDecimalDeserializer'.

 但需要重新打包hessian jar 包。

  b. 在这个 http://blog.csdn.net/jackpk/article/details/43969639 中得知, 该问题已经在4.0.37中修复, 而且当前最新的版本号为4.0.38, 于是升级至后者,不幸的是,问题并没有解决。下载这两个jar包后发现,前者META-INF中包含了a中所提的文件, 但后者中没有。于是最终的解决方案是

  c. 下载4.0.37并包含在项目中,更新pom.xml如下

<dependency>   
<groupId>com.caucho</groupId>
<artifactId>hessian</artifactId>
<version>4.0.37</version>
<scope>system</scope>
<systemPath>${basedir}/src/main/webapp/WEB-INF/lib/hessian-4.0.37.jar</systemPath>
</dependency>

4. Open question

  既然已经在37中修复或workaround,为什么在38中又回滚? 由于时间关系,没有深入研究。希望有了解情况的人给以回复。


posted @ 2016-06-19 18:56  谭金府  阅读(775)  评论(0编辑  收藏  举报