Skip to content

Commit 16fa69c

Browse files
committed
investigate XML.toString() behavior with null JSONObject values
1 parent b06182c commit 16fa69c

1 file changed

Lines changed: 12 additions & 7 deletions

File tree

JSONObjectTest.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1498,22 +1498,26 @@ public void jsonObjectNullOperations() {
14981498
* These are three literal name tokens: ...
14991499
* null
15001500
*
1501-
* There seems to be no best practice to follow, it's all about what we want the code to do.
1501+
* There seems to be no best practice to follow, it's all about what we
1502+
* want the code to do.
15021503
*/
15031504

15041505
// add JSONObject.NULL then convert to string in the manner of XML.toString()
15051506
JSONObject jsonObjectJONull = new JSONObject();
15061507
Object obj = JSONObject.NULL;
15071508
jsonObjectJONull.put("key", obj);
15081509
Object value = jsonObjectJONull.opt("key");
1509-
assertTrue("opt() JSONObject.NULL should find JSONObject.NULL", obj.equals(value));
1510+
assertTrue("opt() JSONObject.NULL should find JSONObject.NULL",
1511+
obj.equals(value));
15101512
value = jsonObjectJONull.get("key");
1511-
assertTrue("get() JSONObject.NULL should find JSONObject.NULL", obj.equals(value));
1513+
assertTrue("get() JSONObject.NULL should find JSONObject.NULL",
1514+
obj.equals(value));
15121515
if (value == null) {
15131516
value = "";
15141517
}
15151518
String string = value instanceof String ? (String)value : null;
1516-
assertTrue("XML toString() should convert JSONObject.NULL to null", string == null);
1519+
assertTrue("XML toString() should convert JSONObject.NULL to null",
1520+
string == null);
15171521

15181522
// now try it with null
15191523
JSONObject jsonObjectNull = new JSONObject();
@@ -1536,11 +1540,12 @@ public void jsonObjectNullOperations() {
15361540
* if the key val is "content", then value.toString() will be
15371541
* called. This will evaluate to "null" for JSONObject.NULL,
15381542
* and the empty string for null.
1539-
* But if the key is anything else, then JSONObject.NULL will be emitted as <key>null</key>
1540-
* and null will be emitted as ""
1543+
* But if the key is anything else, then JSONObject.NULL will be emitted
1544+
* as <key>null</key> and null will be emitted as ""
15411545
*/
15421546
String sJONull = XML.toString(jsonObjectJONull);
1543-
assertTrue("JSONObject.NULL should emit a null value", "<key>null</key>".equals(sJONull));
1547+
assertTrue("JSONObject.NULL should emit a null value",
1548+
"<key>null</key>".equals(sJONull));
15441549
String sNull = XML.toString(jsonObjectNull);
15451550
assertTrue("null should emit an empty string", "".equals(sNull));
15461551
}

0 commit comments

Comments
 (0)