Mercurial > dive4elements > framework
changeset 392:cdc8b7c64856
JSON2XML: Remove extra <map></map> from the XML generated by JSON lists containing only
objects.
artifacts/trunk@4566 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Fri, 01 Jun 2012 09:49:07 +0000 (2012-06-01) |
parents | d5db5483b376 |
children | b7831cefbb62 |
files | ChangeLog artifacts-common/src/main/java/de/intevation/artifacts/common/utils/XMLUtils.java |
diffstat | 2 files changed, 22 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog Sun May 27 10:40:55 2012 +0000 +++ b/ChangeLog Fri Jun 01 09:49:07 2012 +0000 @@ -1,3 +1,9 @@ +2012-06-01 Sascha L. Teichmann <sascha.teichmann@intevation.de> + + * artifacts-common/src/main/java/de/intevation/artifacts/common/utils/XMLUtils.java: + Remove extra <map></map> from the XML generated by JSON lists containing only + objects. + 2012-05-27 Ingo Weinzierl <ingo@intevation.de> Tagged trunk as '2.7'
--- a/artifacts-common/src/main/java/de/intevation/artifacts/common/utils/XMLUtils.java Sun May 27 10:40:55 2012 +0000 +++ b/artifacts-common/src/main/java/de/intevation/artifacts/common/utils/XMLUtils.java Fri Jun 01 09:49:07 2012 +0000 @@ -507,6 +507,14 @@ void add(String key, Object value) { attributes.put(key, value != null ? value.toString() : "null"); } + + int numChildren() { + return children.size(); + } + + Node firstChild() { + return children.get(0); + } } // class BuildResult private static BuildResult recursiveBuild( @@ -516,11 +524,16 @@ BuildResult result = new BuildResult(); for (Object entry: list) { if (entry instanceof Map) { - Element element = document.createElement("map"); BuildResult subResult = recursiveBuild( (Map<String, Object>)entry, document); - subResult.finish(element); - result.add(element); + if (subResult.numChildren() == 1) { + result.add(subResult.firstChild()); + } + else { + Element element = document.createElement("map"); + subResult.finish(element); + result.add(element); + } } else if (entry instanceof List) { Element element = document.createElement("list");