From b795cb83443d7a6153e17f837fe4dcc2a716eb30 Mon Sep 17 00:00:00 2001 From: Tatu Saloranta Date: Thu, 9 Jul 2020 20:51:34 -0700 Subject: One more change wrt #631 --- .../fasterxml/jackson/core/base/ParserBase.java | 44 ++++++++++++++++++---- 1 file changed, 37 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/fasterxml/jackson/core/base/ParserBase.java b/src/main/java/com/fasterxml/jackson/core/base/ParserBase.java index de04e5a2..2e08c0e9 100644 --- a/src/main/java/com/fasterxml/jackson/core/base/ParserBase.java +++ b/src/main/java/com/fasterxml/jackson/core/base/ParserBase.java @@ -581,7 +581,7 @@ public abstract class ParserBase extends ParserMinimalBase /* Numeric accessors of public API /********************************************************** */ - + @Override public Number getNumberValue() throws IOException { @@ -599,13 +599,43 @@ public abstract class ParserBase extends ParserMinimalBase if ((_numTypesValid & NR_BIGINT) != 0) { return _numberBigInt; } - // Shouldn't get this far but if we do + _throwInternal(); + } + + // And then floating point types. But here optimal type + // needs to be big decimal, to avoid losing any data? + if ((_numTypesValid & NR_BIGDECIMAL) != 0) { return _numberBigDecimal; } - - /* And then floating point types. But here optimal type - * needs to be big decimal, to avoid losing any data? - */ + if ((_numTypesValid & NR_DOUBLE) == 0) { // sanity check + _throwInternal(); + } + return _numberDouble; + } + + // NOTE: mostly copied from above + @Override + public Number getNumberValueExact() throws IOException + { + if (_currToken == JsonToken.VALUE_NUMBER_INT) { + if (_numTypesValid == NR_UNKNOWN) { + _parseNumericValue(NR_UNKNOWN); + } + if ((_numTypesValid & NR_INT) != 0) { + return _numberInt; + } + if ((_numTypesValid & NR_LONG) != 0) { + return _numberLong; + } + if ((_numTypesValid & NR_BIGINT) != 0) { + return _numberBigInt; + } + _throwInternal(); + } + // 09-Jul-2020, tatu: [databind#2644] requires we will retain accuracy, so: + if (_numTypesValid == NR_UNKNOWN) { + _parseNumericValue(NR_BIGDECIMAL); + } if ((_numTypesValid & NR_BIGDECIMAL) != 0) { return _numberBigDecimal; } @@ -733,7 +763,7 @@ public abstract class ParserBase extends ParserMinimalBase /* Conversion from textual to numeric representation /********************************************************** */ - + /** * Method that will parse actual numeric value out of a syntactically * valid number value. Type it will parse into depends on whether -- cgit v1.2.3