Esempio n. 1
0
 public BigDecimal read(Kryo kryo, Input input, Class<BigDecimal> type) {
   BigInteger unscaledValue = bigIntegerSerializer.read(kryo, input, BigInteger.class);
   if (unscaledValue == null) return null;
   int scale = input.readInt(false);
   if (type != BigDecimal.class && type != null) {
     // For subclasses, use reflection
     try {
       Constructor<BigDecimal> constructor = type.getConstructor(BigInteger.class, int.class);
       if (!constructor.isAccessible()) {
         try {
           constructor.setAccessible(true);
         } catch (SecurityException se) {
         }
       }
       return constructor.newInstance(unscaledValue, scale);
     } catch (Exception ex) {
       throw new KryoException(ex);
     }
   }
   // fast-path optimizations for BigDecimal constants
   if (unscaledValue == BigInteger.ZERO && scale == 0) {
     return BigDecimal.ZERO;
   }
   // default behaviour
   return new BigDecimal(unscaledValue, scale);
 }
Esempio n. 2
0
 public void write(Kryo kryo, Output output, BigDecimal object) {
   if (object == null) {
     output.writeVarInt(NULL, true);
     return;
   }
   BigDecimal value = (BigDecimal) object;
   // fast-path optimizations for BigDecimal constants
   if (value == BigDecimal.ZERO) {
     bigIntegerSerializer.write(kryo, output, BigInteger.ZERO);
     output.writeInt(0, false); // for backwards compatibility
     return;
   }
   // default behaviour
   bigIntegerSerializer.write(kryo, output, value.unscaledValue());
   output.writeInt(value.scale(), false);
 }