mirror of
https://github.com/stleary/JSON-java.git
synced 2026-04-25 00:00:54 -04:00
Merge pull request #1039 from pratiktiwari13/bugfix/empty-force-list
Fixes the issue of losing the array if an empty forceList element or a tag is in the middle or the end
This commit is contained in:
@@ -391,8 +391,13 @@ public class XML {
|
||||
context.append(tagName, JSONObject.NULL);
|
||||
} else if (jsonObject.length() > 0) {
|
||||
context.append(tagName, jsonObject);
|
||||
} else {
|
||||
} else if(context.isEmpty()) { //avoids resetting the array in case of an empty tag in the middle or end
|
||||
context.put(tagName, new JSONArray());
|
||||
if (jsonObject.isEmpty()){
|
||||
context.append(tagName, "");
|
||||
}
|
||||
} else {
|
||||
context.append(tagName, "");
|
||||
}
|
||||
} else {
|
||||
if (nilAttributeFound) {
|
||||
@@ -451,7 +456,11 @@ public class XML {
|
||||
if (config.getForceList().contains(tagName)) {
|
||||
// Force the value to be an array
|
||||
if (jsonObject.length() == 0) {
|
||||
context.put(tagName, new JSONArray());
|
||||
//avoids resetting the array in case of an empty element in the middle or end
|
||||
if(context.isEmpty()) {
|
||||
context.put(tagName, new JSONArray());
|
||||
}
|
||||
context.append(tagName, "");
|
||||
} else if (jsonObject.length() == 1
|
||||
&& jsonObject.opt(config.getcDataTagName()) != null) {
|
||||
context.append(tagName, jsonObject.opt(config.getcDataTagName()));
|
||||
|
||||
Reference in New Issue
Block a user