Skip to content

Commit

Permalink
add JSONReader.Feature#UseDoubleForDecimals
Browse files Browse the repository at this point in the history
  • Loading branch information
wenshao committed Sep 1, 2024
1 parent 5fca4b8 commit d2a1066
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
12 changes: 11 additions & 1 deletion core/src/main/java/com/alibaba/fastjson2/JSONReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit d2a1066

Please sign in to comment.