IonParser extends JsonParser { @Override public Number getNumberValue() throws IOException { NumberType numberType = getNumberType(); if (numberType == null) { throw new SdkClientException(String.format("Unable to get number value for non-numeric token %s", reader.getType())); } switch (numberType) { case BIG_DECIMAL: return reader.bigDecimalValue(); case BIG_INTEGER: return reader.bigIntegerValue(); case DOUBLE: return reader.doubleValue(); default: throw new SdkClientException(String.format("Unable to get number value for number type %s", numberType)); } } IonParser(IonReader reader, boolean shouldCloseReader); @Override ObjectCodec getCodec(); @Override void setCodec(ObjectCodec c); @Override Version version(); @Override void close(); @Override JsonToken nextToken(); @Override JsonToken nextValue(); @Override JsonParser skipChildren(); @Override boolean isClosed(); @Override JsonToken getCurrentToken(); @Override int getCurrentTokenId(); @Override boolean hasCurrentToken(); @Override boolean hasTokenId(int id); @Override boolean hasToken(JsonToken t); @Override String getCurrentName(); @Override JsonStreamContext getParsingContext(); @Override JsonLocation getTokenLocation(); @Override JsonLocation getCurrentLocation(); @Override void clearCurrentToken(); @Override JsonToken getLastClearedToken(); @Override void overrideCurrentName(String name); @Override String getText(); @Override char[] getTextCharacters(); @Override int getTextLength(); @Override int getTextOffset(); @Override boolean hasTextCharacters(); @Override Number getNumberValue(); @Override NumberType getNumberType(); @Override int getIntValue(); @Override long getLongValue(); @Override BigInteger getBigIntegerValue(); @Override float getFloatValue(); @Override double getDoubleValue(); @Override BigDecimal getDecimalValue(); @Override Object getEmbeddedObject(); @Override byte[] getBinaryValue(Base64Variant bv); @Override String getValueAsString(String defaultValue);  }
@Test public void testGetNumberValue() throws IOException { String integer = String.valueOf(Integer.MAX_VALUE); String lng = String.valueOf(Long.MAX_VALUE); String bigInteger = BigInteger.valueOf(Long.MAX_VALUE).add(BigInteger.ONE).toString(); String flt = String.valueOf(Float.MAX_VALUE); String dbl = String.valueOf(Double.MAX_VALUE); String inf = "1.7976931348623157E309"; String bigDecimal = new BigDecimal(inf).toString(); IonParser parser = parse( integer + " " + lng + " " + bigInteger + " " + flt + " " + dbl + " " + inf + " " + bigDecimal.toLowerCase().replace("e", "D") ); assertEquals(JsonToken.VALUE_NUMBER_INT, parser.nextToken()); assertEquals(integer, parser.getNumberValue().toString()); assertEquals(JsonToken.VALUE_NUMBER_INT, parser.nextToken()); assertEquals(lng, parser.getNumberValue().toString()); assertEquals(JsonToken.VALUE_NUMBER_INT, parser.nextToken()); assertEquals(bigInteger, parser.getNumberValue().toString()); assertEquals(JsonToken.VALUE_NUMBER_FLOAT, parser.nextToken()); assertEquals(flt, parser.getNumberValue().toString()); assertEquals(JsonToken.VALUE_NUMBER_FLOAT, parser.nextToken()); assertEquals(dbl, parser.getNumberValue().toString()); assertEquals(JsonToken.VALUE_NUMBER_FLOAT, parser.nextToken()); assertTrue(Double.isInfinite(parser.getDoubleValue())); assertTrue(Double.isInfinite(parser.getFloatValue())); assertEquals(JsonToken.VALUE_NUMBER_FLOAT, parser.nextToken()); assertEquals(bigDecimal, parser.getNumberValue().toString()); }