Skip to content

Improve #1149 wrt JsonParser.getNumberTypeFP() default implementation #1235

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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