NumberConverter { public static BigDecimal deserializeDecimal(final JsonReader reader) throws IOException { if (reader.last() == '"') { final int len = reader.parseString(); return parseNumberGeneric(reader.chars, len, reader, true); } final int start = reader.scanNumber(); int end = reader.getCurrentIndex(); if (end == reader.length()) { NumberInfo info = readLongNumber(reader, start); return parseNumberGeneric(info.buffer, info.length, reader, false); } int len = end - start; if (len > 18) { return parseNumberGeneric(reader.prepareBuffer(start, len), len, reader, false); } final byte[] buf = reader.buffer; final byte ch = buf[start]; if (ch == '-') { return parseNegativeDecimal(buf, reader, start, end); } return parsePositiveDecimal(buf, reader, start, end); }  static void serializeNullable(@Nullable final Double value, final JsonWriter sw); static void serialize(final double value, final JsonWriter sw); static void serialize(@Nullable final double[] value, final JsonWriter sw); static double deserializeDouble(final JsonReader reader); @SuppressWarnings("unchecked") static ArrayList<Double> deserializeDoubleCollection(final JsonReader reader); static void deserializeDoubleCollection(final JsonReader reader, final Collection<Double> res); @SuppressWarnings("unchecked") static ArrayList<Double> deserializeDoubleNullableCollection(final JsonReader reader); static void deserializeDoubleNullableCollection(final JsonReader reader, final Collection<Double> res); static void serializeNullable(@Nullable final Float value, final JsonWriter sw); static void serialize(final float value, final JsonWriter sw); static void serialize(@Nullable final float[] value, final JsonWriter sw); static float deserializeFloat(final JsonReader reader); @SuppressWarnings("unchecked") static ArrayList<Float> deserializeFloatCollection(final JsonReader reader); static void deserializeFloatCollection(final JsonReader reader, Collection<Float> res); @SuppressWarnings("unchecked") static ArrayList<Float> deserializeFloatNullableCollection(final JsonReader reader); static void deserializeFloatNullableCollection(final JsonReader reader, final Collection<Float> res); static void serializeNullable(@Nullable final Integer value, final JsonWriter sw); static void serialize(final int value, final JsonWriter sw); static void serialize(@Nullable final int[] values, final JsonWriter sw); static void serialize(@Nullable final short[] value, final JsonWriter sw); static short deserializeShort(final JsonReader reader); static int deserializeInt(final JsonReader reader); @SuppressWarnings("unchecked") static ArrayList<Integer> deserializeIntCollection(final JsonReader reader); static int[] deserializeIntArray(final JsonReader reader); static short[] deserializeShortArray(final JsonReader reader); static long[] deserializeLongArray(final JsonReader reader); static float[] deserializeFloatArray(final JsonReader reader); static double[] deserializeDoubleArray(final JsonReader reader); static void deserializeShortCollection(final JsonReader reader, final Collection<Short> res); @SuppressWarnings("unchecked") static ArrayList<Short> deserializeShortNullableCollection(final JsonReader reader); static void deserializeShortNullableCollection(final JsonReader reader, final Collection<Short> res); static void deserializeIntCollection(final JsonReader reader, final Collection<Integer> res); @SuppressWarnings("unchecked") static ArrayList<Integer> deserializeIntNullableCollection(final JsonReader reader); static void deserializeIntNullableCollection(final JsonReader reader, final Collection<Integer> res); static void serializeNullable(@Nullable final Long value, final JsonWriter sw); static void serialize(final long value, final JsonWriter sw); static void serialize(@Nullable final long[] values, final JsonWriter sw); static long deserializeLong(final JsonReader reader); @SuppressWarnings("unchecked") static ArrayList<Long> deserializeLongCollection(final JsonReader reader); static void deserializeLongCollection(final JsonReader reader, final Collection<Long> res); @SuppressWarnings("unchecked") static ArrayList<Long> deserializeLongNullableCollection(final JsonReader reader); static void deserializeLongNullableCollection(final JsonReader reader, final Collection<Long> res); static void serializeNullable(@Nullable final BigDecimal value, final JsonWriter sw); static void serialize(final BigDecimal value, final JsonWriter sw); static BigDecimal deserializeDecimal(final JsonReader reader); static Number deserializeNumber(final JsonReader reader); @SuppressWarnings("unchecked") static ArrayList<BigDecimal> deserializeDecimalCollection(final JsonReader reader); static void deserializeDecimalCollection(final JsonReader reader, final Collection<BigDecimal> res); @SuppressWarnings("unchecked") static ArrayList<BigDecimal> deserializeDecimalNullableCollection(final JsonReader reader); static void deserializeDecimalNullableCollection(final JsonReader reader, final Collection<BigDecimal> res); final static short[] SHORT_EMPTY_ARRAY; final static int[] INT_EMPTY_ARRAY; final static long[] LONG_EMPTY_ARRAY; final static float[] FLOAT_EMPTY_ARRAY; final static double[] DOUBLE_EMPTY_ARRAY; final static Short SHORT_ZERO; final static Integer INT_ZERO; final static Long LONG_ZERO; final static Float FLOAT_ZERO; final static Double DOUBLE_ZERO; static final JsonReader.ReadObject<Double> DOUBLE_READER; static final JsonReader.ReadObject<Double> NULLABLE_DOUBLE_READER; static final JsonWriter.WriteObject<Double> DOUBLE_WRITER; static final JsonReader.ReadObject<double[]> DOUBLE_ARRAY_READER; static final JsonWriter.WriteObject<double[]> DOUBLE_ARRAY_WRITER; static final JsonReader.ReadObject<Float> FLOAT_READER; static final JsonReader.ReadObject<Float> NULLABLE_FLOAT_READER; static final JsonWriter.WriteObject<Float> FLOAT_WRITER; static final JsonReader.ReadObject<float[]> FLOAT_ARRAY_READER; static final JsonWriter.WriteObject<float[]> FLOAT_ARRAY_WRITER; static final JsonReader.ReadObject<Integer> INT_READER; static final JsonReader.ReadObject<Integer> NULLABLE_INT_READER; static final JsonWriter.WriteObject<Integer> INT_WRITER; static final JsonReader.ReadObject<int[]> INT_ARRAY_READER; static final JsonWriter.WriteObject<int[]> INT_ARRAY_WRITER; static final JsonReader.ReadObject<Short> SHORT_READER; static final JsonReader.ReadObject<Short> NULLABLE_SHORT_READER; static final JsonWriter.WriteObject<Short> SHORT_WRITER; static final JsonReader.ReadObject<short[]> SHORT_ARRAY_READER; static final JsonWriter.WriteObject<short[]> SHORT_ARRAY_WRITER; static final JsonReader.ReadObject<Long> LONG_READER; static final JsonReader.ReadObject<Long> NULLABLE_LONG_READER; static final JsonWriter.WriteObject<Long> LONG_WRITER; static final JsonReader.ReadObject<long[]> LONG_ARRAY_READER; static final JsonWriter.WriteObject<long[]> LONG_ARRAY_WRITER; static final JsonReader.ReadObject<BigDecimal> DecimalReader; static final JsonWriter.WriteObject<BigDecimal> DecimalWriter; }
@Test public void testBigDecimalDeserializationWithProcessStreamWhenAtBoundaryAndMore() throws IOException { final byte[] input = "0.112233445566778899,1".getBytes("UTF-8"); final BigDecimal expected = new BigDecimal("0.112233445566778899"); final JsonReader<Object> jr = dslJson.newReader(new byte[20]); jr.process(new ByteArrayInputStream(input)); jr.read(); final BigDecimal actual = NumberConverter.deserializeDecimal(jr); Assert.assertEquals(expected, actual); }
@Test public void testBigDecimalDeserializationWithProcessBuffer() throws IOException { final BigDecimal expected = new BigDecimal("0.112233445566778899001122334455667788993"); final byte[] input = "0.112233445566778899001122334455667788993".getBytes("UTF-8"); final JsonReader<Object> jr = dslJson.newReader(new byte[20]); jr.process(input, input.length); jr.read(); final BigDecimal actual = NumberConverter.deserializeDecimal(jr); Assert.assertEquals(expected, actual); }
@Test public void testBigDecimalDeserializationWithProcessBufferWhenAtBoundary() throws IOException { final byte[] input = "0.112233445566778899".getBytes("UTF-8"); final BigDecimal expected = new BigDecimal("0.112233445566778899"); final JsonReader<Object> jr = dslJson.newReader(new byte[20]); jr.process(input, input.length); jr.read(); final BigDecimal actual = NumberConverter.deserializeDecimal(jr); Assert.assertEquals(expected, actual); }
@Test public void testBigDecimalDeserializationWithProcessBufferWhenAtBoundaryAndMore() throws IOException { final byte[] input = "0.112233445566778899,1".getBytes("UTF-8"); final BigDecimal expected = new BigDecimal("0.112233445566778899"); final JsonReader<Object> jr = dslJson.newReader(new byte[20]); jr.process(input, input.length); jr.read(); final BigDecimal actual = NumberConverter.deserializeDecimal(jr); Assert.assertEquals(expected, actual); }
@Test public void testBigDecimalDeserializationWithNewStream() throws IOException { final BigDecimal expected = new BigDecimal("0.112233445566778899001122334455667788993"); final byte[] input = "0.112233445566778899001122334455667788993".getBytes("UTF-8"); final JsonReader<Object> jr = dslJson.newReader(new ByteArrayInputStream(input), new byte[20]); jr.read(); final BigDecimal actual = NumberConverter.deserializeDecimal(jr); Assert.assertEquals(expected, actual); }
@Test public void testBigDecimalDeserializationWithNewStreamWhenAtBoundary() throws IOException { final byte[] input = "0.112233445566778899".getBytes("UTF-8"); final BigDecimal expected = new BigDecimal("0.112233445566778899"); final JsonReader<Object> jr = dslJson.newReader(new ByteArrayInputStream(input), new byte[20]); jr.read(); final BigDecimal actual = NumberConverter.deserializeDecimal(jr); Assert.assertEquals(expected, actual); }
@Test public void testBigDecimalDeserializationWithNewStreamWhenAtBoundaryAndMore() throws IOException { final byte[] input = "0.112233445566778899,1".getBytes("UTF-8"); final BigDecimal expected = new BigDecimal("0.112233445566778899"); final JsonReader<Object> jr = dslJson.newReader(new ByteArrayInputStream(input), new byte[20]); jr.read(); final BigDecimal actual = NumberConverter.deserializeDecimal(jr); Assert.assertEquals(expected, actual); }
@Test public void testBigDecimalDeserializationWithProcessStream() throws IOException { final BigDecimal expected = new BigDecimal("0.112233445566778899001122334455667788993"); final byte[] input = "\"0.112233445566778899001122334455667788993\",[".getBytes("UTF-8"); final JsonReader<Object> jr = dslJson.newReader(new byte[20]); jr.process(new ByteArrayInputStream(input)); jr.read(); final BigDecimal actual = NumberConverter.deserializeDecimal(jr); Assert.assertEquals(expected, actual); }
@Test public void testBigDecimalDeserializationWithProcessStreamWhenAtBoundary() throws IOException { final byte[] input = "0.112233445566778899".getBytes("UTF-8"); final BigDecimal expected = new BigDecimal("0.112233445566778899"); final JsonReader<Object> jr = dslJson.newReader(new byte[20]); jr.process(new ByteArrayInputStream(input)); jr.read(); final BigDecimal actual = NumberConverter.deserializeDecimal(jr); Assert.assertEquals(expected, actual); }