@@ -1597,7 +1597,7 @@ public boolean isNaN() {
1597
1597
public Number getNumberValue () throws JacksonException
1598
1598
{
1599
1599
if (_numTypesValid == NR_UNKNOWN ) {
1600
- _checkNumericValue (NR_UNKNOWN ); // will also check event type
1600
+ _checkNumericValue (); // will also check event type
1601
1601
}
1602
1602
// Separate types for int types
1603
1603
if (_currToken == JsonToken .VALUE_NUMBER_INT ) {
@@ -1636,9 +1636,6 @@ public final Number getNumberValueExact() throws JacksonException {
1636
1636
@ Override
1637
1637
public NumberType getNumberType () throws JacksonException
1638
1638
{
1639
- if (_numTypesValid == NR_UNKNOWN ) {
1640
- _checkNumericValue (NR_UNKNOWN ); // will also check event type
1641
- }
1642
1639
if (_currToken == JsonToken .VALUE_NUMBER_INT ) {
1643
1640
if ((_numTypesValid & NR_LONG ) != 0 ) {
1644
1641
return NumberType .LONG ;
@@ -1655,13 +1652,17 @@ public NumberType getNumberType() throws JacksonException
1655
1652
* double as type if no explicit call has been made to access
1656
1653
* data as BD?
1657
1654
*/
1658
- if ((_numTypesValid & NR_BIGDECIMAL ) != 0 ) {
1659
- return NumberType .BIG_DECIMAL ;
1660
- }
1661
- if ((_numTypesValid & NR_DOUBLE ) != 0 ) {
1662
- return NumberType .DOUBLE ;
1655
+ if (_currToken == JsonToken .VALUE_NUMBER_FLOAT ) {
1656
+ if ((_numTypesValid & NR_BIGDECIMAL ) != 0 ) {
1657
+ return NumberType .BIG_DECIMAL ;
1658
+ }
1659
+ if ((_numTypesValid & NR_DOUBLE ) != 0 ) {
1660
+ return NumberType .DOUBLE ;
1661
+ }
1662
+ return NumberType .FLOAT ;
1663
1663
}
1664
- return NumberType .FLOAT ;
1664
+
1665
+ return null ;
1665
1666
}
1666
1667
1667
1668
@ Override // since 2.17
@@ -1686,11 +1687,9 @@ public int getIntValue() throws JacksonException
1686
1687
{
1687
1688
if ((_numTypesValid & NR_INT ) == 0 ) {
1688
1689
if (_numTypesValid == NR_UNKNOWN ) { // not parsed at all
1689
- _checkNumericValue (NR_INT ); // will also check event type
1690
- }
1691
- if ((_numTypesValid & NR_INT ) == 0 ) { // wasn't an int natively?
1692
- convertNumberToInt (); // let's make it so, if possible
1690
+ _checkNumericValue (); // will also check event type
1693
1691
}
1692
+ convertNumberToInt (); // let's make it so, if possible
1694
1693
}
1695
1694
return _numberInt ;
1696
1695
}
@@ -1700,11 +1699,9 @@ public long getLongValue() throws JacksonException
1700
1699
{
1701
1700
if ((_numTypesValid & NR_LONG ) == 0 ) {
1702
1701
if (_numTypesValid == NR_UNKNOWN ) {
1703
- _checkNumericValue (NR_LONG );
1704
- }
1705
- if ((_numTypesValid & NR_LONG ) == 0 ) {
1706
- convertNumberToLong ();
1702
+ _checkNumericValue ();
1707
1703
}
1704
+ convertNumberToLong ();
1708
1705
}
1709
1706
return _numberLong ;
1710
1707
}
@@ -1714,11 +1711,9 @@ public BigInteger getBigIntegerValue() throws JacksonException
1714
1711
{
1715
1712
if ((_numTypesValid & NR_BIGINT ) == 0 ) {
1716
1713
if (_numTypesValid == NR_UNKNOWN ) {
1717
- _checkNumericValue (NR_BIGINT );
1718
- }
1719
- if ((_numTypesValid & NR_BIGINT ) == 0 ) {
1720
- convertNumberToBigInteger ();
1714
+ _checkNumericValue ();
1721
1715
}
1716
+ convertNumberToBigInteger ();
1722
1717
}
1723
1718
return _numberBigInt ;
1724
1719
}
@@ -1728,11 +1723,9 @@ public float getFloatValue() throws JacksonException
1728
1723
{
1729
1724
if ((_numTypesValid & NR_FLOAT ) == 0 ) {
1730
1725
if (_numTypesValid == NR_UNKNOWN ) {
1731
- _checkNumericValue (NR_FLOAT );
1732
- }
1733
- if ((_numTypesValid & NR_FLOAT ) == 0 ) {
1734
- convertNumberToFloat ();
1726
+ _checkNumericValue ();
1735
1727
}
1728
+ convertNumberToFloat ();
1736
1729
}
1737
1730
// Bounds/range checks would be tricky here, so let's not bother even trying...
1738
1731
/*
@@ -1748,11 +1741,9 @@ public double getDoubleValue() throws JacksonException
1748
1741
{
1749
1742
if ((_numTypesValid & NR_DOUBLE ) == 0 ) {
1750
1743
if (_numTypesValid == NR_UNKNOWN ) {
1751
- _checkNumericValue (NR_DOUBLE );
1752
- }
1753
- if ((_numTypesValid & NR_DOUBLE ) == 0 ) {
1754
- convertNumberToDouble ();
1744
+ _checkNumericValue ();
1755
1745
}
1746
+ convertNumberToDouble ();
1756
1747
}
1757
1748
return _numberDouble ;
1758
1749
}
@@ -1762,11 +1753,9 @@ public BigDecimal getDecimalValue() throws JacksonException
1762
1753
{
1763
1754
if ((_numTypesValid & NR_BIGDECIMAL ) == 0 ) {
1764
1755
if (_numTypesValid == NR_UNKNOWN ) {
1765
- _checkNumericValue (NR_BIGDECIMAL );
1766
- }
1767
- if ((_numTypesValid & NR_BIGDECIMAL ) == 0 ) {
1768
- convertNumberToBigDecimal ();
1756
+ _checkNumericValue ();
1769
1757
}
1758
+ convertNumberToBigDecimal ();
1770
1759
}
1771
1760
return _numberBigDecimal ;
1772
1761
}
@@ -1777,13 +1766,12 @@ public BigDecimal getDecimalValue() throws JacksonException
1777
1766
/**********************************************************************
1778
1767
*/
1779
1768
1780
- protected void _checkNumericValue (int expType ) throws JacksonException
1769
+ protected void _checkNumericValue () throws JacksonException
1781
1770
{
1782
1771
// Int or float?
1783
- if (_currToken == JsonToken .VALUE_NUMBER_INT || _currToken = = JsonToken .VALUE_NUMBER_FLOAT ) {
1784
- return ;
1772
+ if (_currToken != JsonToken .VALUE_NUMBER_INT && _currToken ! = JsonToken .VALUE_NUMBER_FLOAT ) {
1773
+ throw _constructReadException ( "Current token (%s) not numeric, cannot use numeric value accessors" , _currToken ) ;
1785
1774
}
1786
- _reportError ("Current token (" +_currToken +") not numeric, can not use numeric value accessors" );
1787
1775
}
1788
1776
1789
1777
protected void convertNumberToInt () throws JacksonException
0 commit comments