@@ -35,6 +35,7 @@ of this software and associated documentation files (the "Software"), to deal
3535import static org .mockito .Mockito .when ;
3636
3737import java .io .IOException ;
38+ import java .io .Reader ;
3839import java .io .StringReader ;
3940import java .io .StringWriter ;
4041import java .math .BigDecimal ;
@@ -55,6 +56,7 @@ of this software and associated documentation files (the "Software"), to deal
5556import org .json .JSONException ;
5657import org .json .JSONObject ;
5758import org .json .JSONPointerException ;
59+ import org .json .JSONTokener ;
5860import org .json .XML ;
5961import org .json .junit .data .BrokenToString ;
6062import 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