Skip to content

Commit f7ec6b9

Browse files
authored
Merge pull request #131 from BlazingTwist/fix-json-regression
fix a regression when parsing Json with decimals
2 parents 86e15d6 + c2ef1c7 commit f7ec6b9

File tree

3 files changed

+65
-2
lines changed

3 files changed

+65
-2
lines changed

src/aya/ext/json/JSONUtils.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,8 @@ private static Obj toObj(Object object, JSONParams params) throws AyaException {
124124
return new List(arr);
125125
} else if (object instanceof Integer) {
126126
return Num.fromInt((Integer)object);
127-
} else if (object instanceof Double) {
128-
return new Num((Double)object);
127+
} else if (object instanceof Number) {
128+
return new Num(((Number)object).doubleValue());
129129
} else if (object instanceof String) {
130130
String str = (String)object;
131131
if (params.parse_symbol && str.startsWith("::")) {

test/std/test_json.aya

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
.# see https://www.json.org/json-en.html
2+
"""{
3+
"emptyObj": {},
4+
"valuesArray": [
5+
{
6+
"string": "foo"
7+
},
8+
{
9+
"number0": 0,
10+
"number0N": -0,
11+
"numberInt": 12,
12+
"numberIntN": -12,
13+
"numberFr": 0.12,
14+
"numberFrN": -0.12,
15+
"numberExp": 23.45E3,
16+
"numberExpN": 23.45e-3,
17+
"numberNExp": -23.45e3,
18+
"numberNExpN": -23.45E-3
19+
},
20+
[1, 2, 3],
21+
true,
22+
false,
23+
null
24+
]
25+
}""" :(json.loads) :json_obj;
26+
27+
:{
28+
:{} :"emptyObj";
29+
[
30+
:{
31+
"foo" :"string";
32+
}
33+
:{
34+
0 :"number0";
35+
-0 :"number0N";
36+
12 :"numberInt";
37+
-12 :"numberIntN";
38+
0.12 :"numberFr";
39+
-0.12 :"numberFrN";
40+
:23.45e3 :"numberExp";
41+
:23.45e-3 :"numberExpN";
42+
:-23.45e3 :"numberNExp";
43+
:-23.45e-3 :"numberNExpN";
44+
}
45+
[1 2 3]
46+
1
47+
0
48+
::__json_null
49+
] :"valuesArray";
50+
} :aya_obj;
51+
52+
53+
[
54+
55+
{ json_obj aya_obj }
56+
57+
{
58+
aya_obj :(json.dumps) :(json.loads)
59+
aya_obj
60+
}
61+
62+
] :# { test.test }

test/test.aya

+1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
"enum"
5555
"csv"
5656
"io"
57+
"json"
5758
"la"
5859
"map"
5960
"matrix"

0 commit comments

Comments
 (0)