Skip to content

Commit d2a1066

Browse files
committed
add JSONReader.Feature#UseDoubleForDecimals
1 parent 5fca4b8 commit d2a1066

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

core/src/main/java/com/alibaba/fastjson2/JSONReader.java

+11-1
Original file line numberDiff line numberDiff line change
@@ -2977,6 +2977,10 @@ public final Number getNumber() {
29772977
decimalStr + "E" + exponent);
29782978
}
29792979

2980+
if ((context.features & Feature.UseDoubleForDecimals.mask) != 0) {
2981+
return decimal.doubleValue();
2982+
}
2983+
29802984
return decimal;
29812985
}
29822986
case JSON_TYPE_BIG_DEC: {
@@ -4562,8 +4566,14 @@ public enum Feature {
45624566

45634567
/**
45644568
* Feature that disables the support for single quote.
4569+
* @since 2.0.53
4570+
*/
4571+
DisableSingleQuote(1L << 31L),
4572+
4573+
/**
4574+
* @since 2.0.53
45654575
*/
4566-
DisableSingleQuote(1 << 31);
4576+
UseDoubleForDecimals(1L << 32L);
45674577

45684578
public final long mask;
45694579

fastjson1-compatible/src/main/java/com/alibaba/fastjson/parser/JSONScanner.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public void config(Feature feature, boolean state) {
113113
rawFeature = JSONReader.Feature.UseNativeObject;
114114
break;
115115
case UseBigDecimal:
116-
rawFeature = JSONReader.Feature.UseBigDecimalForDoubles;
116+
rawFeature = JSONReader.Feature.UseDoubleForDecimals;
117117
not = true;
118118
break;
119119
case OrderedField:
@@ -166,7 +166,7 @@ public boolean isEnabled(Feature feature) {
166166
rawFeature = JSONReader.Feature.UseNativeObject;
167167
break;
168168
case UseBigDecimal:
169-
return !reader.isEnabled(JSONReader.Feature.UseBigDecimalForDoubles);
169+
return !reader.isEnabled(JSONReader.Feature.UseDoubleForDecimals);
170170
default:
171171
break;
172172
}

0 commit comments

Comments
 (0)