@@ -203,6 +203,8 @@ public abstract class ParserBase extends ParserMinimalBase
203
203
204
204
protected BigDecimal _numberBigDecimal ;
205
205
206
+ protected String _numberString ;
207
+
206
208
// And then other information about value itself
207
209
208
210
/**
@@ -607,7 +609,7 @@ public Number getNumberValue() throws IOException
607
609
return _numberLong ;
608
610
}
609
611
if ((_numTypesValid & NR_BIGINT ) != 0 ) {
610
- return _numberBigInt ;
612
+ return getBigInteger () ;
611
613
}
612
614
_throwInternal ();
613
615
}
@@ -641,7 +643,7 @@ public Number getNumberValueExact() throws IOException
641
643
return _numberLong ;
642
644
}
643
645
if ((_numTypesValid & NR_BIGINT ) != 0 ) {
644
- return _numberBigInt ;
646
+ return getBigInteger () ;
645
647
}
646
648
_throwInternal ();
647
649
}
@@ -731,7 +733,7 @@ public BigInteger getBigIntegerValue() throws IOException
731
733
convertNumberToBigInteger ();
732
734
}
733
735
}
734
- return _numberBigInt ;
736
+ return getBigInteger () ;
735
737
}
736
738
737
739
@ Override
@@ -930,8 +932,9 @@ private void _parseSlowInt(int expType) throws IOException
930
932
_numberDouble = NumberInput .parseDouble (numStr , isEnabled (Feature .USE_FAST_DOUBLE_PARSER ));
931
933
_numTypesValid = NR_DOUBLE ;
932
934
} else {
933
- // nope, need the heavy guns... (rare case)
934
- _numberBigInt = NumberInput .parseBigInteger (numStr );
935
+ // nope, need the heavy guns... (rare case) - since Jackson v2.14, BigInteger parsing is lazy
936
+ _numberBigInt = null ;
937
+ _numberString = numStr ;
935
938
_numTypesValid = NR_BIGINT ;
936
939
}
937
940
}
@@ -968,11 +971,12 @@ protected void convertNumberToInt() throws IOException
968
971
}
969
972
_numberInt = result ;
970
973
} else if ((_numTypesValid & NR_BIGINT ) != 0 ) {
971
- if (BI_MIN_INT .compareTo (_numberBigInt ) > 0
972
- || BI_MAX_INT .compareTo (_numberBigInt ) < 0 ) {
974
+ final BigInteger bigInteger = getBigInteger ();
975
+ if (BI_MIN_INT .compareTo (bigInteger ) > 0
976
+ || BI_MAX_INT .compareTo (bigInteger ) < 0 ) {
973
977
reportOverflowInt ();
974
978
}
975
- _numberInt = _numberBigInt .intValue ();
979
+ _numberInt = bigInteger .intValue ();
976
980
} else if ((_numTypesValid & NR_DOUBLE ) != 0 ) {
977
981
// Need to check boundaries
978
982
if (_numberDouble < MIN_INT_D || _numberDouble > MAX_INT_D ) {
@@ -996,11 +1000,12 @@ protected void convertNumberToLong() throws IOException
996
1000
if ((_numTypesValid & NR_INT ) != 0 ) {
997
1001
_numberLong = (long ) _numberInt ;
998
1002
} else if ((_numTypesValid & NR_BIGINT ) != 0 ) {
999
- if (BI_MIN_LONG .compareTo (_numberBigInt ) > 0
1000
- || BI_MAX_LONG .compareTo (_numberBigInt ) < 0 ) {
1003
+ final BigInteger bigInteger = getBigInteger ();
1004
+ if (BI_MIN_LONG .compareTo (bigInteger ) > 0
1005
+ || BI_MAX_LONG .compareTo (bigInteger ) < 0 ) {
1001
1006
reportOverflowLong ();
1002
1007
}
1003
- _numberLong = _numberBigInt .longValue ();
1008
+ _numberLong = bigInteger .longValue ();
1004
1009
} else if ((_numTypesValid & NR_DOUBLE ) != 0 ) {
1005
1010
// Need to check boundaries
1006
1011
if (_numberDouble < MIN_LONG_D || _numberDouble > MAX_LONG_D ) {
@@ -1047,7 +1052,7 @@ protected void convertNumberToDouble() throws IOException
1047
1052
if ((_numTypesValid & NR_BIGDECIMAL ) != 0 ) {
1048
1053
_numberDouble = _numberBigDecimal .doubleValue ();
1049
1054
} else if ((_numTypesValid & NR_BIGINT ) != 0 ) {
1050
- _numberDouble = _numberBigInt .doubleValue ();
1055
+ _numberDouble = getBigInteger () .doubleValue ();
1051
1056
} else if ((_numTypesValid & NR_LONG ) != 0 ) {
1052
1057
_numberDouble = (double ) _numberLong ;
1053
1058
} else if ((_numTypesValid & NR_INT ) != 0 ) {
@@ -1071,7 +1076,7 @@ protected void convertNumberToFloat() throws IOException
1071
1076
if ((_numTypesValid & NR_BIGDECIMAL ) != 0 ) {
1072
1077
_numberFloat = _numberBigDecimal .floatValue ();
1073
1078
} else if ((_numTypesValid & NR_BIGINT ) != 0 ) {
1074
- _numberFloat = _numberBigInt .floatValue ();
1079
+ _numberFloat = getBigInteger () .floatValue ();
1075
1080
} else if ((_numTypesValid & NR_LONG ) != 0 ) {
1076
1081
_numberFloat = (float ) _numberLong ;
1077
1082
} else if ((_numTypesValid & NR_INT ) != 0 ) {
@@ -1098,7 +1103,7 @@ protected void convertNumberToBigDecimal() throws IOException
1098
1103
*/
1099
1104
_numberBigDecimal = NumberInput .parseBigDecimal (getText ());
1100
1105
} else if ((_numTypesValid & NR_BIGINT ) != 0 ) {
1101
- _numberBigDecimal = new BigDecimal (_numberBigInt );
1106
+ _numberBigDecimal = new BigDecimal (getBigInteger () );
1102
1107
} else if ((_numTypesValid & NR_LONG ) != 0 ) {
1103
1108
_numberBigDecimal = BigDecimal .valueOf (_numberLong );
1104
1109
} else if ((_numTypesValid & NR_INT ) != 0 ) {
@@ -1345,4 +1350,15 @@ protected void loadMoreGuaranteed() throws IOException {
1345
1350
1346
1351
// Can't declare as deprecated, for now, but shouldn't be needed
1347
1352
protected void _finishString () throws IOException { }
1353
+
1354
+ private BigInteger getBigInteger () {
1355
+ if (_numberBigInt != null ) {
1356
+ return _numberBigInt ;
1357
+ } else if (_numberString == null ) {
1358
+ throw new IllegalStateException ("cannot get BigInteger from current parser state" );
1359
+ }
1360
+ _numberBigInt = NumberInput .parseBigInteger (_numberString );
1361
+ _numberString = null ;
1362
+ return _numberBigInt ;
1363
+ }
1348
1364
}
0 commit comments