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); }
@Override public BigDecimal read(final ObjectDataInput in) throws IOException { BigInteger bigInt = bigIntegerSerializer.read(in); int scale = in.readInt(); return new BigDecimal(bigInt, scale); }