@@ -2011,7 +2011,7 @@ public boolean isNaN() {
2011
2011
public Number getNumberValue () throws JacksonException
2012
2012
{
2013
2013
if (_numTypesValid == NR_UNKNOWN ) {
2014
- _checkNumericValue (NR_UNKNOWN ); // will also check event type
2014
+ _checkNumericValue (); // will also check event type
2015
2015
}
2016
2016
// Separate types for int types
2017
2017
if (_currToken == JsonToken .VALUE_NUMBER_INT ) {
@@ -2050,9 +2050,6 @@ public final Number getNumberValueExact() throws JacksonException {
2050
2050
@ Override
2051
2051
public NumberType getNumberType () throws JacksonException
2052
2052
{
2053
- if (_numTypesValid == NR_UNKNOWN ) {
2054
- _checkNumericValue (NR_UNKNOWN ); // will also check event type
2055
- }
2056
2053
if (_currToken == JsonToken .VALUE_NUMBER_INT ) {
2057
2054
if ((_numTypesValid & NR_INT ) != 0 ) {
2058
2055
return NumberType .INT ;
@@ -2062,23 +2059,25 @@ public NumberType getNumberType() throws JacksonException
2062
2059
}
2063
2060
return NumberType .BIG_INTEGER ;
2064
2061
}
2065
-
2066
2062
/* And then floating point types. Here optimal type
2067
2063
* needs to be big decimal, to avoid losing any data?
2068
2064
* However... using BD is slow, so let's allow returning
2069
2065
* double as type if no explicit call has been made to access
2070
2066
* data as BD?
2071
2067
*/
2072
- if ((_numTypesValid & NR_BIGDECIMAL ) != 0 ) {
2073
- return NumberType .BIG_DECIMAL ;
2074
- }
2075
- if ((_numTypesValid & NR_DOUBLE ) != 0 ) {
2076
- return NumberType .DOUBLE ;
2068
+ if (_currToken == JsonToken .VALUE_NUMBER_FLOAT ) {
2069
+ if ((_numTypesValid & NR_BIGDECIMAL ) != 0 ) {
2070
+ return NumberType .BIG_DECIMAL ;
2071
+ }
2072
+ if ((_numTypesValid & NR_DOUBLE ) != 0 ) {
2073
+ return NumberType .DOUBLE ;
2074
+ }
2075
+ return NumberType .FLOAT ;
2077
2076
}
2078
- return NumberType . FLOAT ;
2077
+ return null ;
2079
2078
}
2080
2079
2081
- @ Override // since 2.17
2080
+ @ Override
2082
2081
public NumberTypeFP getNumberTypeFP () throws JacksonException
2083
2082
{
2084
2083
if (_currToken == JsonToken .VALUE_NUMBER_FLOAT ) {
@@ -2106,11 +2105,9 @@ public float getFloatValue() throws JacksonException
2106
2105
{
2107
2106
if ((_numTypesValid & NR_FLOAT ) == 0 ) {
2108
2107
if (_numTypesValid == NR_UNKNOWN ) {
2109
- _checkNumericValue (NR_FLOAT );
2110
- }
2111
- if ((_numTypesValid & NR_FLOAT ) == 0 ) {
2112
- convertNumberToFloat ();
2108
+ _checkNumericValue ();
2113
2109
}
2110
+ convertNumberToFloat ();
2114
2111
}
2115
2112
// Bounds/range checks would be tricky here, so let's not bother even trying...
2116
2113
/*
@@ -2144,13 +2141,12 @@ protected int _parseIntValue() throws JacksonException {
2144
2141
/**********************************************************************
2145
2142
*/
2146
2143
2147
- protected void _checkNumericValue (int expType ) throws JacksonException
2144
+ protected void _checkNumericValue () throws JacksonException
2148
2145
{
2149
2146
// Int or float?
2150
- if (_currToken == JsonToken .VALUE_NUMBER_INT || _currToken = = JsonToken .VALUE_NUMBER_FLOAT ) {
2151
- return ;
2147
+ if (_currToken != JsonToken .VALUE_NUMBER_INT && _currToken ! = JsonToken .VALUE_NUMBER_FLOAT ) {
2148
+ _reportError ( "Current token (" + _currToken + ") not numeric, can not use numeric value accessors" ) ;
2152
2149
}
2153
- _reportError ("Current token (" +currentToken ()+") not numeric, can not use numeric value accessors" );
2154
2150
}
2155
2151
2156
2152
@ Override // due to addition of Float as type
0 commit comments