* Test the toString of JSONObject.
* Use the value to construct a new object and verify contents match.
*/
public void test_toString() {
HashMap map = new HashMap();
JSONObject jObject = null;
JSONObject jObject2 = null;
try {
System.setProperty("org.apache.wink.common.model.json.factory.impl", "org.apache.wink.json4j.compat.impl.ApacheJSONFactory");
JSONFactory factory = JSONFactory.newInstance();
jObject = factory.createJSONObject("{\"foo\": \"bar\", \"number\": 1, \"bool\":true}");
jObject2 = factory.createJSONObject(jObject.toString());
} catch (Exception ex) {
ex.printStackTrace();
assertTrue(false);
}
try{
assertTrue(jObject != jObject2);
assertTrue(jObject.length() == jObject2.length());
assertTrue(jObject.getString("foo").equals(jObject2.getString("foo")));
assertTrue(jObject.getBoolean("bool") == jObject2.getBoolean("bool"));
assertTrue(jObject.getInt("number") == jObject2.getInt("number"));
}catch(JSONException jex){
jex.printStackTrace();
assertTrue(false);
}
}