Skip to content

Commit

Permalink
Improve #1149 wrt JsonParser.getNumberTypeFP() default implementation (
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder authored Mar 4, 2024
1 parent 1994217 commit d29507f
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/main/java/com/fasterxml/jackson/core/JsonParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -1769,15 +1769,30 @@ public Object getNumberValueDeferred() throws IOException {
* {@link JsonToken#VALUE_NUMBER_FLOAT}, returns
* one of {@link NumberTypeFP} constants; otherwise returns
* {@link NumberTypeFP#UNKNOWN}.
*<p>
* Default implementation as of Jackson 2.x will call {@link #getNumberType()}
* and translate types -- this needs to be overriden actual implementations
* if this is not sufficient (which it usually is not for textual formats).
*
* @return Type of current number, if parser points to numeric token; {@code null} otherwise
* @return Type of current floating-point number, if parser points to numeric token;
* {@link NumberTypeFP#UNKNOWN} otherwise.
*
* @throws IOException for low-level read issues, or
* {@link JsonParseException} for decoding problems
*
* @since 2.17
*/
public NumberTypeFP getNumberTypeFP() throws IOException {
NumberType nt = getNumberType();
if (nt == NumberType.BIG_DECIMAL) {
return NumberTypeFP.BIG_DECIMAL;
}
if (nt == NumberType.DOUBLE) {
return NumberTypeFP.DOUBLE64;
}
if (nt == NumberType.FLOAT) {
return NumberTypeFP.FLOAT32;
}
return NumberTypeFP.UNKNOWN;
}

Expand Down

0 comments on commit d29507f

Please sign in to comment.