From d29507fe5f3aa696e483a4de416e8195bb4af47c Mon Sep 17 00:00:00 2001 From: Tatu Saloranta Date: Sun, 3 Mar 2024 22:36:26 -0800 Subject: [PATCH] Improve #1149 wrt JsonParser.getNumberTypeFP() default implementation (#1235) --- .../com/fasterxml/jackson/core/JsonParser.java | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/fasterxml/jackson/core/JsonParser.java b/src/main/java/com/fasterxml/jackson/core/JsonParser.java index 3aebea959d..03f0189fc1 100644 --- a/src/main/java/com/fasterxml/jackson/core/JsonParser.java +++ b/src/main/java/com/fasterxml/jackson/core/JsonParser.java @@ -1769,8 +1769,13 @@ public Object getNumberValueDeferred() throws IOException { * {@link JsonToken#VALUE_NUMBER_FLOAT}, returns * one of {@link NumberTypeFP} constants; otherwise returns * {@link NumberTypeFP#UNKNOWN}. + *

+ * 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 @@ -1778,6 +1783,16 @@ public Object getNumberValueDeferred() throws IOException { * @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; }