Skip to content

Commit 6013161

Browse files
committed
Merge pull request alibaba#139 from pepov/master
Fix number parsing in objects
2 parents c736460 + 0656a5a commit 6013161

File tree

5 files changed

+15
-1
lines changed

5 files changed

+15
-1
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,6 @@
22
/.project
33
/.settings
44
/.classpath
5+
/.idea
6+
*.iml
7+

src/main/java/com/alibaba/fastjson/parser/DefaultJSONParser.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ public final Object parseObject(final Map object, Object fieldName) {
402402
if (lexer.token() == JSONToken.LITERAL_INT) {
403403
value = lexer.integerValue();
404404
} else {
405-
value = lexer.numberValue();
405+
value = lexer.decimalValue(isEnabled(Feature.UseBigDecimal));
406406
}
407407

408408
object.put(key, value);

src/main/java/com/alibaba/fastjson/parser/JSONLexer.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ public interface JSONLexer {
5454

5555
void scanString();
5656

57+
@Deprecated
5758
Number numberValue();
5859

5960
int intValue();

src/main/java/com/alibaba/fastjson/parser/JSONLexerBase.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2931,6 +2931,7 @@ public final BigDecimal decimalValue() {
29312931
return new BigDecimal(numberString());
29322932
}
29332933

2934+
@Deprecated
29342935
public final Number numberValue() {
29352936
char type = charAt(np + sp - 1);
29362937

src/test/java/com/alibaba/json/bvt/DefaultJSONParserTest.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package com.alibaba.json.bvt;
1717

1818
import java.util.HashMap;
19+
import java.util.Map;
1920

2021
import org.junit.Assert;
2122
import junit.framework.TestCase;
@@ -34,6 +35,14 @@ public void test_double() {
3435
Assert.assertEquals(3.4D, result);
3536
}
3637

38+
public void test_double_in_object() {
39+
DefaultJSONParser parser = new DefaultJSONParser("{\"double\":3.4}");
40+
parser.config(Feature.UseBigDecimal, false);
41+
Assert.assertEquals("{\"double\":3.4}", parser.getInput());
42+
Object result = parser.parse();
43+
Assert.assertEquals(3.4D, ((Map) result).get("double"));
44+
}
45+
3746
public void test_error() {
3847
Exception error = null;
3948
try {

0 commit comments

Comments
 (0)