diff options
author | Tatu Saloranta <tatu.saloranta@iki.fi> | 2020-07-09 20:51:34 -0700 |
---|---|---|
committer | Tatu Saloranta <tatu.saloranta@iki.fi> | 2020-07-09 20:51:34 -0700 |
commit | b795cb83443d7a6153e17f837fe4dcc2a716eb30 (patch) | |
tree | 164c57baa201b76ab31117e5d3bcdf4262d92011 | |
parent | 90379ffc88110d3bd4a5452f31ba571087639bb5 (diff) | |
download | jackson-core-b795cb83443d7a6153e17f837fe4dcc2a716eb30.tar.gz |
One more change wrt #631
-rw-r--r-- | src/main/java/com/fasterxml/jackson/core/base/ParserBase.java | 44 |
1 files 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 |