Mantis - Hessian
Viewing Issue Advanced Details
3920 major always 02-27-10 17:54 02-08-16 23:24
aloksingh  
 
normal  
new 4.0.3  
open  
none    
none  
0003920: BigDecimal objects are incorrectly serialized
Serializing/Deserializing BigDecimal objects doesn't work correctly

Ex:
BigDecimal object = new BigDecimal("12474639.945458954");
Hessian2Output os = new Hessian2Output(null);
os.setSerializerFactory(new SerializerFactory());
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
os.init(buffer);
os.writeObject(object);
os.close();
byte[] bytes = buffer.toByteArray();

 Hessian2Input is = new Hessian2Input(new ByteArrayInputStream(bytes));
 BigDecimal newObject = (T) is.readObject();
 is.close();

assert object.equals(newObject)

The final assertion should not fail.

Notes
(0004650)
qrilka   
07-01-10 05:46   
I'm using hessian 4.0.7
Looking into the source code shows that serilizers/deserilizers for BigDecimal are commented out (quite a strange decision from my p.o.v.) but it's quite easy to solve - just create META-INF/hessian/serializers and META-INF/hessian/deserializers with corresponding classnames. An example for that can be seen in resin.jar (for resin4)
(0004680)
p_wright   
07-22-10 09:59   
I can also confirm this with 4.0.7... the result is a BigDecimal with a value of 0.0... which causes some problems since we use BigDecimals to accurately represent sums of money.
(0004709)
groblochon   
08-13-10 01:16   
I solve this bug with 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'.
(0006673)
Nathanael Sommer-Koch   
02-08-16 23:24   
We just encountered the same problem in our project. How come this issue is still not resolved after 6 years?
And why is there a Deserializer but no Serializer?
(0006674)
Nathanael Sommer-Koch   
02-08-16 23:24   
We just encountered the same problem in our project. How come this issue is still not resolved after 6 years?
And why is there a Deserializer but no Serializer?