From ba6c4089ea14e5927b696f758cf67576396dba5c Mon Sep 17 00:00:00 2001 From: "John J. Aylward" Date: Thu, 25 Jun 2020 11:42:07 -0400 Subject: [PATCH 1/2] fixes #531 Add test result to confirm that #531 is working in latest version. --- src/test/java/org/json/junit/JSONObjectTest.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/test/java/org/json/junit/JSONObjectTest.java b/src/test/java/org/json/junit/JSONObjectTest.java index c24d138c6..224c61e13 100644 --- a/src/test/java/org/json/junit/JSONObjectTest.java +++ b/src/test/java/org/json/junit/JSONObjectTest.java @@ -35,6 +35,7 @@ of this software and associated documentation files (the "Software"), to deal import static org.mockito.Mockito.when; import java.io.IOException; +import java.io.Reader; import java.io.StringReader; import java.io.StringWriter; import java.math.BigDecimal; @@ -55,6 +56,7 @@ of this software and associated documentation files (the "Software"), to deal import org.json.JSONException; import org.json.JSONObject; import org.json.JSONPointerException; +import org.json.JSONTokener; import org.json.XML; import org.json.junit.data.BrokenToString; import org.json.junit.data.ExceptionalBean; @@ -3079,6 +3081,19 @@ public void testWierdListBean() { assertNotNull(jo.get("ALL")); } + public void testObjectToBigDecimal() { + double value = 1412078745.01074; + Reader reader = new StringReader("[{\"value\": " + value + "}]"); + JSONTokener tokener = new JSONTokener(reader); + JSONArray array = new JSONArray(tokener); + JSONObject jsonObject = array.getJSONObject(0); + + BigDecimal current = jsonObject.getBigDecimal("value"); + BigDecimal wantedValue = BigDecimal.valueOf(value); + + assertEquals(current, wantedValue); + } + /** * Tests the exception portions of populateMap. */ From f9908a6adbf52c6b783cf148f36225c05f4c0936 Mon Sep 17 00:00:00 2001 From: "John J. Aylward" Date: Thu, 25 Jun 2020 11:50:59 -0400 Subject: [PATCH 2/2] adds comment on test case to document why it was added. --- src/test/java/org/json/junit/JSONObjectTest.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/test/java/org/json/junit/JSONObjectTest.java b/src/test/java/org/json/junit/JSONObjectTest.java index 224c61e13..56e110edd 100644 --- a/src/test/java/org/json/junit/JSONObjectTest.java +++ b/src/test/java/org/json/junit/JSONObjectTest.java @@ -3081,6 +3081,10 @@ public void testWierdListBean() { assertNotNull(jo.get("ALL")); } + /** + * Sample test case from https://github.com/stleary/JSON-java/issues/531 + * which verifies that no regression in double/BigDecimal support is present. + */ public void testObjectToBigDecimal() { double value = 1412078745.01074; Reader reader = new StringReader("[{\"value\": " + value + "}]");