Skip to content

Commit b795cb8

Browse files
committed
One more change wrt #631
1 parent 90379ff commit b795cb8

File tree

1 file changed

+37
-7
lines changed

1 file changed

+37
-7
lines changed

src/main/java/com/fasterxml/jackson/core/base/ParserBase.java

+37-7
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ public boolean isNaN() {
581581
/* Numeric accessors of public API
582582
/**********************************************************
583583
*/
584-
584+
585585
@Override
586586
public Number getNumberValue() throws IOException
587587
{
@@ -599,13 +599,43 @@ public Number getNumberValue() throws IOException
599599
if ((_numTypesValid & NR_BIGINT) != 0) {
600600
return _numberBigInt;
601601
}
602-
// Shouldn't get this far but if we do
602+
_throwInternal();
603+
}
604+
605+
// And then floating point types. But here optimal type
606+
// needs to be big decimal, to avoid losing any data?
607+
if ((_numTypesValid & NR_BIGDECIMAL) != 0) {
603608
return _numberBigDecimal;
604609
}
605-
606-
/* And then floating point types. But here optimal type
607-
* needs to be big decimal, to avoid losing any data?
608-
*/
610+
if ((_numTypesValid & NR_DOUBLE) == 0) { // sanity check
611+
_throwInternal();
612+
}
613+
return _numberDouble;
614+
}
615+
616+
// NOTE: mostly copied from above
617+
@Override
618+
public Number getNumberValueExact() throws IOException
619+
{
620+
if (_currToken == JsonToken.VALUE_NUMBER_INT) {
621+
if (_numTypesValid == NR_UNKNOWN) {
622+
_parseNumericValue(NR_UNKNOWN);
623+
}
624+
if ((_numTypesValid & NR_INT) != 0) {
625+
return _numberInt;
626+
}
627+
if ((_numTypesValid & NR_LONG) != 0) {
628+
return _numberLong;
629+
}
630+
if ((_numTypesValid & NR_BIGINT) != 0) {
631+
return _numberBigInt;
632+
}
633+
_throwInternal();
634+
}
635+
// 09-Jul-2020, tatu: [databind#2644] requires we will retain accuracy, so:
636+
if (_numTypesValid == NR_UNKNOWN) {
637+
_parseNumericValue(NR_BIGDECIMAL);
638+
}
609639
if ((_numTypesValid & NR_BIGDECIMAL) != 0) {
610640
return _numberBigDecimal;
611641
}
@@ -733,7 +763,7 @@ public BigDecimal getDecimalValue() throws IOException
733763
/* Conversion from textual to numeric representation
734764
/**********************************************************
735765
*/
736-
766+
737767
/**
738768
* Method that will parse actual numeric value out of a syntactically
739769
* valid number value. Type it will parse into depends on whether

0 commit comments

Comments
 (0)