Skip to content

Commit 6ddaa13

Browse files
authored
Merge pull request stleary#532 from johnjaylward/CheckBigDecimalSupport
Verifies BigDecimal support does not have a regression
2 parents 9de9743 + f9908a6 commit 6ddaa13

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/test/java/org/json/junit/JSONObjectTest.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ of this software and associated documentation files (the "Software"), to deal
3535
import static org.mockito.Mockito.when;
3636

3737
import java.io.IOException;
38+
import java.io.Reader;
3839
import java.io.StringReader;
3940
import java.io.StringWriter;
4041
import java.math.BigDecimal;
@@ -55,6 +56,7 @@ of this software and associated documentation files (the "Software"), to deal
5556
import org.json.JSONException;
5657
import org.json.JSONObject;
5758
import org.json.JSONPointerException;
59+
import org.json.JSONTokener;
5860
import org.json.XML;
5961
import org.json.junit.data.BrokenToString;
6062
import org.json.junit.data.ExceptionalBean;
@@ -3079,6 +3081,23 @@ public void testWierdListBean() {
30793081
assertNotNull(jo.get("ALL"));
30803082
}
30813083

3084+
/**
3085+
* Sample test case from https://github.com/stleary/JSON-java/issues/531
3086+
* which verifies that no regression in double/BigDecimal support is present.
3087+
*/
3088+
public void testObjectToBigDecimal() {
3089+
double value = 1412078745.01074;
3090+
Reader reader = new StringReader("[{\"value\": " + value + "}]");
3091+
JSONTokener tokener = new JSONTokener(reader);
3092+
JSONArray array = new JSONArray(tokener);
3093+
JSONObject jsonObject = array.getJSONObject(0);
3094+
3095+
BigDecimal current = jsonObject.getBigDecimal("value");
3096+
BigDecimal wantedValue = BigDecimal.valueOf(value);
3097+
3098+
assertEquals(current, wantedValue);
3099+
}
3100+
30823101
/**
30833102
* Tests the exception portions of populateMap.
30843103
*/

0 commit comments

Comments
 (0)