1
0
Fork 0
mirror of https://github.com/ethauvin/JSON-java.git synced 2025-06-17 07:50:52 -07:00

Merge pull request #30 from stleary/confirmValueToStringFix

Fix tabs, add valueToString() test to JSONObjectTest
This commit is contained in:
Sean Leary 2015-10-31 04:00:52 -05:00
commit c578216844
2 changed files with 202 additions and 183 deletions

View file

@ -1471,6 +1471,25 @@ public class JSONObjectTest {
jsonArray.toString().equals(JSONObject.valueToString(array)));
}
/**
* Confirm that https://github.com/douglascrockford/JSON-java/issues/167 is fixed.
* The following code was throwing a ClassCastException in the
* JSONObject(Map<String, Object>) constructor
*/
@Test
public void valueToStringConfirmException() {
String expectedStr = "{\"1\":\"myValue\"}";
Map<Integer, String> myMap = new HashMap<Integer, String>();
myMap.put(1, "myValue");
// this is the test, it should not throw an exception
String str = JSONObject.valueToString(myMap);
// confirm result, just in case
JSONObject jsonObject = new JSONObject(str);
JSONObject expectedJsonObject = new JSONObject(expectedStr);
Util.compareActualVsExpectedJsonObjects(jsonObject,
expectedJsonObject);
}
/**
* Exercise the JSONObject wrap() method. Sometimes wrap() will change
* the object being wrapped, other times not. The purpose of wrap() is