From d2a10668321b6489bfe296aad0f4dea7858576cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=AB=98=E9=93=81?= Date: Sun, 1 Sep 2024 14:51:12 +0800 Subject: [PATCH] add JSONReader.Feature#UseDoubleForDecimals --- .../main/java/com/alibaba/fastjson2/JSONReader.java | 12 +++++++++++- .../com/alibaba/fastjson/parser/JSONScanner.java | 4 ++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/com/alibaba/fastjson2/JSONReader.java b/core/src/main/java/com/alibaba/fastjson2/JSONReader.java index 5e78db9be7..bfee9d411f 100644 --- a/core/src/main/java/com/alibaba/fastjson2/JSONReader.java +++ b/core/src/main/java/com/alibaba/fastjson2/JSONReader.java @@ -2977,6 +2977,10 @@ public final Number getNumber() { decimalStr + "E" + exponent); } + if ((context.features & Feature.UseDoubleForDecimals.mask) != 0) { + return decimal.doubleValue(); + } + return decimal; } case JSON_TYPE_BIG_DEC: { @@ -4562,8 +4566,14 @@ public enum Feature { /** * Feature that disables the support for single quote. + * @since 2.0.53 + */ + DisableSingleQuote(1L << 31L), + + /** + * @since 2.0.53 */ - DisableSingleQuote(1 << 31); + UseDoubleForDecimals(1L << 32L); public final long mask; diff --git a/fastjson1-compatible/src/main/java/com/alibaba/fastjson/parser/JSONScanner.java b/fastjson1-compatible/src/main/java/com/alibaba/fastjson/parser/JSONScanner.java index 3328a3e3fe..9f11576468 100644 --- a/fastjson1-compatible/src/main/java/com/alibaba/fastjson/parser/JSONScanner.java +++ b/fastjson1-compatible/src/main/java/com/alibaba/fastjson/parser/JSONScanner.java @@ -113,7 +113,7 @@ public void config(Feature feature, boolean state) { rawFeature = JSONReader.Feature.UseNativeObject; break; case UseBigDecimal: - rawFeature = JSONReader.Feature.UseBigDecimalForDoubles; + rawFeature = JSONReader.Feature.UseDoubleForDecimals; not = true; break; case OrderedField: @@ -166,7 +166,7 @@ public boolean isEnabled(Feature feature) { rawFeature = JSONReader.Feature.UseNativeObject; break; case UseBigDecimal: - return !reader.isEnabled(JSONReader.Feature.UseBigDecimalForDoubles); + return !reader.isEnabled(JSONReader.Feature.UseDoubleForDecimals); default: break; }