New JSONObject.optJSONObject method with defaultValue parameter

This commit is contained in:
Niels Frederiksen
2021-06-23 15:15:00 +02:00
parent 4571978840
commit f91d0c8a52
2 changed files with 18 additions and 6 deletions

View File

@@ -2404,8 +2404,8 @@ public class JSONObjectTest {
MyEnum.VAL1.equals(jsonObject.optEnum(MyEnum.class, "myKey", MyEnum.VAL1)));
assertTrue("optJSONArray() should return null ",
null==jsonObject.optJSONArray("myKey"));
assertTrue("optJSONObject() should return null ",
null==jsonObject.optJSONObject("myKey"));
assertTrue("optJSONObject() should return default JSONObject ",
jsonObject.optJSONObject("myKey", new JSONObject("{\"testKey\":\"testValue\"}")).getString("testKey").equals("testValue"));
assertTrue("optLong() should return default long",
42l == jsonObject.optLong("myKey", 42l));
assertTrue("optDouble() should return default double",
@@ -2440,8 +2440,8 @@ public class JSONObjectTest {
MyEnum.VAL1.equals(jsonObject.optEnum(MyEnum.class, "myKey", MyEnum.VAL1)));
assertTrue("optJSONArray() should return null ",
null==jsonObject.optJSONArray("myKey"));
assertTrue("optJSONObject() should return null ",
null==jsonObject.optJSONObject("myKey"));
assertTrue("optJSONObject() should return default JSONObject ",
jsonObject.optJSONObject("myKey", new JSONObject("{\"testKey\":\"testValue\"}")).getString("testKey").equals("testValue"));
assertTrue("optLong() should return default long",
42l == jsonObject.optLong("myKey", 42l));
assertTrue("optDouble() should return default double",