Skip to content

Commit d520210

Browse files
Sean LearySean Leary
authored andcommitted
Added one more example to XMLTest clarifyCurrentBehavior()
1 parent 8982888 commit d520210

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

src/test/java/org/json/junit/XMLTest.java

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1400,16 +1400,30 @@ public void testWithWhitespaceTrimmingEnabledByDefault() {
14001400
@Test
14011401
public void clarifyCurrentBehavior() {
14021402

1403+
// Behavior documented in #826
1404+
// After reverting the code, amount is stored as numeric, and phone is stored as string
1405+
String str1 =
1406+
" <datatypes>\n" +
1407+
" <telephone>0123456789</telephone>\n" +
1408+
" <amount>0.1230</amount>\n" +
1409+
" <boolean>true</boolean>\n" +
1410+
" </datatypes>";
1411+
JSONObject jsonObject1 = XML.toJSONObject(str1,
1412+
new XMLParserConfiguration().withKeepStrings(false));
1413+
assertEquals(jsonObject1.getJSONObject("datatypes").getFloat("amount"), 0.123, .1);
1414+
assertEquals(jsonObject1.getJSONObject("datatypes").getString("telephone"), "0123456789");
1415+
1416+
14031417
// Behavior documented in #852
14041418
// After reverting the code, value is still stored as a number. This is due to how XML.isDecimalNotation() works
14051419
// and is probably a bug. JSONObject has a similar problem.
1406-
String str = "<color> <color_type>primary</color_type> <value>008E97</value> </color>";
1407-
JSONObject jsonObject = XML.toJSONObject(str);
1408-
assertEquals(jsonObject.getJSONObject("color").getLong("value"), 0e897, .1);
1420+
String str2 = "<color> <color_type>primary</color_type> <value>008E97</value> </color>";
1421+
JSONObject jsonObject2 = XML.toJSONObject(str2);
1422+
assertEquals(jsonObject2.getJSONObject("color").getLong("value"), 0e897, .1);
14091423

14101424
// Workaround for now is to use keepStrings
1411-
JSONObject jsonObject1 = XML.toJSONObject(str, new XMLParserConfiguration().withKeepStrings(true));
1412-
assertEquals(jsonObject1.getJSONObject("color").getString("value"), "008E97");
1425+
JSONObject jsonObject3 = XML.toJSONObject(str2, new XMLParserConfiguration().withKeepStrings(true));
1426+
assertEquals(jsonObject3.getJSONObject("color").getString("value"), "008E97");
14131427
}
14141428

14151429
}

0 commit comments

Comments
 (0)