mirror of
https://gitee.com/dromara/hutool.git
synced 2025-04-05 17:37:59 +08:00
commit
f4d73ee66e
@ -87,13 +87,13 @@ public class JSONXMLSerializer {
|
|||||||
} else if (value instanceof JSONArray) {
|
} else if (value instanceof JSONArray) {
|
||||||
for (Object val : (JSONArray) value) {
|
for (Object val : (JSONArray) value) {
|
||||||
if (val instanceof JSONArray) {
|
if (val instanceof JSONArray) {
|
||||||
sb.append(wrapWithTag(toXml(val), key));
|
sb.append(wrapWithTag(toXml(val, null, contentKeys), key));
|
||||||
} else {
|
} else {
|
||||||
sb.append(toXml(val, key));
|
sb.append(toXml(val, key, contentKeys));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
sb.append(toXml(value, key));
|
sb.append(toXml(value, key, contentKeys));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -111,7 +111,7 @@ public class JSONXMLSerializer {
|
|||||||
// XML does not have good support for arrays. If an array
|
// XML does not have good support for arrays. If an array
|
||||||
// appears in a place where XML is lacking, synthesize an
|
// appears in a place where XML is lacking, synthesize an
|
||||||
// <array> element.
|
// <array> element.
|
||||||
sb.append(toXml(val, tagName == null ? "array" : tagName));
|
sb.append(toXml(val, tagName == null ? "array" : tagName, contentKeys));
|
||||||
}
|
}
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
20
hutool-json/src/test/java/cn/hutool/json/IssueI676IT.java
Normal file
20
hutool-json/src/test/java/cn/hutool/json/IssueI676IT.java
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
package cn.hutool.json;
|
||||||
|
|
||||||
|
import cn.hutool.core.io.resource.ResourceUtil;
|
||||||
|
import cn.hutool.core.util.XmlUtil;
|
||||||
|
import cn.hutool.json.xml.JSONXMLSerializer;
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static javax.xml.xpath.XPathConstants.STRING;
|
||||||
|
|
||||||
|
public class IssueI676IT {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void parseXMLTest() {
|
||||||
|
final JSONObject jsonObject = JSONUtil.parseObj(ResourceUtil.readUtf8Str("issueI676IT.json"));
|
||||||
|
String xmlStr = JSONXMLSerializer.toXml(jsonObject, null, (String) null);
|
||||||
|
String content = String.valueOf(XmlUtil.getByXPath("/page/orderItems[1]/content", XmlUtil.readXML(xmlStr), STRING));
|
||||||
|
Assert.assertEquals(content, "bar1");
|
||||||
|
}
|
||||||
|
}
|
19
hutool-json/src/test/resources/issueI676IT.json
Normal file
19
hutool-json/src/test/resources/issueI676IT.json
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
{
|
||||||
|
"page": {
|
||||||
|
"pageSize": 33,
|
||||||
|
"currentPage": 81,
|
||||||
|
"totalSize": 49,
|
||||||
|
"orderItems": [
|
||||||
|
{
|
||||||
|
"asc": true,
|
||||||
|
"columnName": "foo",
|
||||||
|
"content": "bar1"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"asc": false,
|
||||||
|
"columnName": "foo",
|
||||||
|
"content": "bar2"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user