mirror of
https://github.com/stleary/JSON-java.git
synced 2025-08-03 03:15:32 -04:00
Pass test case for empty tag with forceList
This commit is contained in:
parent
3f9b53fee4
commit
e638955034
@ -415,7 +415,7 @@ public class XML {
|
||||
if (parse(x, jsonObject, tagName, config)) {
|
||||
if (config.getForceList().contains(tagName)) {
|
||||
if (jsonObject.length() == 0) {
|
||||
context.append(tagName, "");
|
||||
context.put(tagName, new JSONArray());
|
||||
} else if (jsonObject.length() == 1
|
||||
&& jsonObject.opt(config.getcDataTagName()) != null) {
|
||||
context.append(tagName, jsonObject.opt(config.getcDataTagName()));
|
||||
|
@ -919,7 +919,8 @@ public class XMLConfigurationTest {
|
||||
" </address>\n"+
|
||||
"</addresses>";
|
||||
|
||||
String expectedStr = "{\"addresses\":[{\"address\":{\"name\":\"Sherlock Holmes\"}}]}";
|
||||
String expectedStr =
|
||||
"{\"addresses\":[{\"address\":{\"name\":\"Sherlock Holmes\"}}]}";
|
||||
|
||||
Set<String> forceList = new HashSet<String>();
|
||||
forceList.add("addresses");
|
||||
@ -974,7 +975,25 @@ public class XMLConfigurationTest {
|
||||
|
||||
Util.compareActualVsExpectedJsonObjects(jsonObject, expetedJsonObject);
|
||||
}
|
||||
@Test
|
||||
public void testEmptyForceList() {
|
||||
String xmlStr =
|
||||
"<addresses></addresses>";
|
||||
|
||||
String expectedStr =
|
||||
"{\"addresses\":[]}";
|
||||
|
||||
Set<String> forceList = new HashSet<String>();
|
||||
forceList.add("addresses");
|
||||
|
||||
XMLParserConfiguration config =
|
||||
new XMLParserConfiguration()
|
||||
.withForceList(forceList);
|
||||
JSONObject jsonObject = XML.toJSONObject(xmlStr, config);
|
||||
JSONObject expetedJsonObject = new JSONObject(expectedStr);
|
||||
|
||||
Util.compareActualVsExpectedJsonObjects(jsonObject, expetedJsonObject);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method, given an input string and expected result,
|
||||
|
Loading…
x
Reference in New Issue
Block a user