Skip to content

Commit 747e783

Browse files
authored
Improved toXml
1 parent 417358e commit 747e783

3 files changed

Lines changed: 22 additions & 2 deletions

File tree

src/main/java/com/github/underscore/U.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2260,7 +2260,8 @@ public static FetchResponse fetch(
22602260
}
22612261
}
22622262

2263-
public static int readWithRetry(java.io.InputStream inputStream, byte[] buffer) throws java.io.IOException {
2263+
public static int readWithRetry(java.io.InputStream inputStream, byte[] buffer)
2264+
throws java.io.IOException {
22642265
java.io.IOException lastException = null;
22652266
for (int attempt = 0; attempt < 2; attempt++) {
22662267
try {

src/main/java/com/github/underscore/Xml.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1193,7 +1193,8 @@ private static void checkLocalMap(
11931193
|| localMap2.size() != 1
11941194
|| XmlValue.getMapKey(localMap2).startsWith("-")
11951195
|| XmlValue.getMapValue(localMap2) instanceof List) {
1196-
if (ROOT.equals(XmlValue.getMapKey(localMap2))) {
1196+
if (ROOT.equals(XmlValue.getMapKey(localMap2))
1197+
&& XmlValue.getMapValue(localMap2) instanceof List) {
11971198
writeArray((List) XmlValue.getMapValue(localMap2), builder, arrayTrue);
11981199
} else {
11991200
XmlObject.writeXml(

src/test/java/com/github/underscore/LodashTest.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1113,6 +1113,24 @@ void xmpToJson5() {
11131113
U.xmlToJson("<Comment stringValue=\"============================\"/>"));
11141114
}
11151115

1116+
@Test
1117+
void xmpToJson6() {
1118+
assertEquals(
1119+
"{\n"
1120+
+ " \"root\": {\n"
1121+
+ " \"a\": 1\n"
1122+
+ " },\n"
1123+
+ " \"omit-xml-declaration\": \"yes\"\n"
1124+
+ "}",
1125+
U.xmlToJson("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
1126+
+ "<root>\n"
1127+
+ " <root>\n"
1128+
+ " <a number=\"true\">1</a>\n"
1129+
+ " </root>\n"
1130+
+ " <omit-xml-declaration>yes</omit-xml-declaration>\n"
1131+
+ "</root>"));
1132+
}
1133+
11161134
@Test
11171135
void xmlToJsonMinimum() {
11181136
assertEquals(

0 commit comments

Comments
 (0)