Skip to content
Snippets Groups Projects
Commit 3f23fb8c authored by Jesse Wilson's avatar Jesse Wilson Committed by Thomas Koch
Browse files

Javadocs for JSONObject.

Change-Id: I5ec9df6a3a9baac8f4f498890cd35feff774737a
parent 6e65d0ae
No related branches found
No related tags found
No related merge requests found
......@@ -58,7 +58,7 @@ class JSON {
return ((Number) value).intValue();
} else if (value instanceof String) {
try {
return Double.valueOf((String) value).intValue();
return (int) Double.parseDouble((String) value);
} catch (NumberFormatException e) {
}
}
......@@ -72,7 +72,7 @@ class JSON {
return ((Number) value).longValue();
} else if (value instanceof String) {
try {
return Double.valueOf((String) value).longValue();
return (long) Double.parseDouble((String) value);
} catch (NumberFormatException e) {
}
}
......
This diff is collapsed.
......@@ -453,6 +453,53 @@ public class JSONObjectTest extends TestCase {
assertEquals(null, object.optJSONObject("foo"));
}
public void testNullCoercionToString() throws JSONException {
JSONObject object = new JSONObject();
object.put("foo", JSONObject.NULL);
assertEquals("null", object.getString("foo"));
}
public void testArrayCoercion() throws JSONException {
JSONObject object = new JSONObject();
object.put("foo", "[true]");
try {
object.getJSONArray("foo");
fail();
} catch (JSONException e) {
}
}
public void testObjectCoercion() throws JSONException {
JSONObject object = new JSONObject();
object.put("foo", "{}");
try {
object.getJSONObject("foo");
fail();
} catch (JSONException e) {
}
}
public void testAccumulateValueChecking() throws JSONException {
JSONObject object = new JSONObject();
try {
object.accumulate("foo", Double.NaN);
fail();
} catch (JSONException e) {
}
object.accumulate("foo", 1);
try {
object.accumulate("foo", Double.NaN);
fail();
} catch (JSONException e) {
}
object.accumulate("foo", 2);
try {
object.accumulate("foo", Double.NaN);
fail();
} catch (JSONException e) {
}
}
public void testToJSONArray() throws JSONException {
JSONObject object = new JSONObject();
Object value = new Object();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment