diff --git a/src/main/java/com/github/underscore/Xml.java b/src/main/java/com/github/underscore/Xml.java
index bcc40854..793da57c 100644
--- a/src/main/java/com/github/underscore/Xml.java
+++ b/src/main/java/com/github/underscore/Xml.java
@@ -1189,23 +1189,11 @@ private static void checkLocalMap(
} else {
localMap2 = localMap;
}
- if (localMap2 == null
- || localMap2.size() != 1
- || XmlValue.getMapKey(localMap2).startsWith("-")
- || XmlValue.getMapValue(localMap2) instanceof List) {
- if (ROOT.equals(XmlValue.getMapKey(localMap2))
- && XmlValue.getMapValue(localMap2) instanceof List) {
- writeArray((List) XmlValue.getMapValue(localMap2), builder, arrayTrue);
- } else {
- XmlObject.writeXml(
- localMap2,
- getRootName(localMap2, newRootName),
- builder,
- false,
- new LinkedHashSet<>(),
- false,
- arrayTrue);
- }
+ if (localMap2 != null
+ && localMap2.size() == 1
+ && ROOT.equals(XmlValue.getMapKey(localMap2))
+ && XmlValue.getMapValue(localMap2) instanceof List) {
+ writeArray((List) XmlValue.getMapValue(localMap2), builder, arrayTrue);
} else {
XmlObject.writeXml(
localMap2,
diff --git a/src/test/java/com/github/underscore/LodashTest.java b/src/test/java/com/github/underscore/LodashTest.java
index cef5094c..bf1fbe9b 100644
--- a/src/test/java/com/github/underscore/LodashTest.java
+++ b/src/test/java/com/github/underscore/LodashTest.java
@@ -698,7 +698,7 @@ void fetchGetHttps() {
U.FetchResponse result =
U.fetch(
"https://raw.githubusercontent.com/javadev/underscore-java/refs/heads/"
- + "main/src/test/resources/example.json");
+ + "main/src/test/resources/example.json");
assertEquals(
"{\n"
+ " \"fruit\": \"Apple\",\n"
@@ -793,7 +793,7 @@ public int read(byte[] b) throws IOException {
@Test
void testSuccessfulReadOnFirstAttempt() throws IOException {
- java.io.InputStream inputStream = new TestInputStream(new int[]{100}, null);
+ java.io.InputStream inputStream = new TestInputStream(new int[] {100}, null);
byte[] buffer = new byte[1024];
int result = U.readWithRetry(inputStream, buffer);
assertEquals(100, result);
@@ -801,10 +801,10 @@ void testSuccessfulReadOnFirstAttempt() throws IOException {
@Test
void testSuccessfulReadOnSecondAttempt() throws IOException {
- java.io.InputStream inputStream = new TestInputStream(
- new int[]{0, 50},
- new IOException[]{new IOException("First failed"), null}
- );
+ java.io.InputStream inputStream =
+ new TestInputStream(
+ new int[] {0, 50},
+ new IOException[] {new IOException("First failed"), null});
byte[] buffer = new byte[1024];
int result = U.readWithRetry(inputStream, buffer);
assertEquals(50, result);
@@ -812,23 +812,26 @@ void testSuccessfulReadOnSecondAttempt() throws IOException {
@Test
void testBothAttemptsFailWithIOException() {
- java.io.InputStream inputStream = new TestInputStream(
- null,
- new IOException[]{
- new IOException("First attempt failed"),
- new IOException("Second attempt failed")
- }
- );
+ java.io.InputStream inputStream =
+ new TestInputStream(
+ null,
+ new IOException[] {
+ new IOException("First attempt failed"),
+ new IOException("Second attempt failed")
+ });
byte[] buffer = new byte[1024];
- IOException thrown = assertThrows(IOException.class, () -> {
- U.readWithRetry(inputStream, buffer);
- });
+ IOException thrown =
+ assertThrows(
+ IOException.class,
+ () -> {
+ U.readWithRetry(inputStream, buffer);
+ });
assertEquals("Second attempt failed", thrown.getMessage());
}
@Test
void testReadReturnsMinusOne() throws IOException {
- java.io.InputStream inputStream = new TestInputStream(new int[]{-1}, null);
+ java.io.InputStream inputStream = new TestInputStream(new int[] {-1}, null);
byte[] buffer = new byte[1024];
int result = U.readWithRetry(inputStream, buffer);
assertEquals(-1, result);
@@ -836,7 +839,7 @@ void testReadReturnsMinusOne() throws IOException {
@Test
void testReadReturnsZero() throws IOException {
- java.io.InputStream inputStream = new TestInputStream(new int[]{0}, null);
+ java.io.InputStream inputStream = new TestInputStream(new int[] {0}, null);
byte[] buffer = new byte[1024];
int result = U.readWithRetry(inputStream, buffer);
assertEquals(0, result);
@@ -1122,13 +1125,31 @@ void xmpToJson6() {
+ " },\n"
+ " \"omit-xml-declaration\": \"yes\"\n"
+ "}",
- U.xmlToJson("\n"
- + "\n"
- + " \n"
- + " 1\n"
- + " \n"
- + " yes\n"
- + ""));
+ U.xmlToJson(
+ "\n"
+ + "\n"
+ + " \n"
+ + " 1\n"
+ + " \n"
+ + " yes\n"
+ + ""));
+ assertEquals(
+ "{\n"
+ + " \"root\": [\n"
+ + " {\n"
+ + " \"a\": 1\n"
+ + " }\n"
+ + " ],\n"
+ + " \"omit-xml-declaration\": \"yes\"\n"
+ + "}",
+ U.xmlToJson(
+ "\n"
+ + "\n"
+ + " \n"
+ + " 1\n"
+ + " \n"
+ + " yes\n"
+ + ""));
}
@Test