Skip to content

Commit d29507f

Browse files
authored
Improve #1149 wrt JsonParser.getNumberTypeFP() default implementation (#1235)
1 parent 1994217 commit d29507f

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/main/java/com/fasterxml/jackson/core/JsonParser.java

+16-1
Original file line numberDiff line numberDiff line change
@@ -1769,15 +1769,30 @@ public Object getNumberValueDeferred() throws IOException {
17691769
* {@link JsonToken#VALUE_NUMBER_FLOAT}, returns
17701770
* one of {@link NumberTypeFP} constants; otherwise returns
17711771
* {@link NumberTypeFP#UNKNOWN}.
1772+
*<p>
1773+
* Default implementation as of Jackson 2.x will call {@link #getNumberType()}
1774+
* and translate types -- this needs to be overriden actual implementations
1775+
* if this is not sufficient (which it usually is not for textual formats).
17721776
*
1773-
* @return Type of current number, if parser points to numeric token; {@code null} otherwise
1777+
* @return Type of current floating-point number, if parser points to numeric token;
1778+
* {@link NumberTypeFP#UNKNOWN} otherwise.
17741779
*
17751780
* @throws IOException for low-level read issues, or
17761781
* {@link JsonParseException} for decoding problems
17771782
*
17781783
* @since 2.17
17791784
*/
17801785
public NumberTypeFP getNumberTypeFP() throws IOException {
1786+
NumberType nt = getNumberType();
1787+
if (nt == NumberType.BIG_DECIMAL) {
1788+
return NumberTypeFP.BIG_DECIMAL;
1789+
}
1790+
if (nt == NumberType.DOUBLE) {
1791+
return NumberTypeFP.DOUBLE64;
1792+
}
1793+
if (nt == NumberType.FLOAT) {
1794+
return NumberTypeFP.FLOAT32;
1795+
}
17811796
return NumberTypeFP.UNKNOWN;
17821797
}
17831798

0 commit comments

Comments
 (0)