diff --git a/README.md b/README.md
index a4cb4f8..765393e 100644
--- a/README.md
+++ b/README.md
@@ -3,7 +3,7 @@
underscore-java17
=================
-[](https://central.sonatype.com/artifact/com.github.javadev/underscore17/1.75)
+[](https://central.sonatype.com/artifact/com.github.javadev/underscore17/1.76)
[ ](https://github.com/javadev/underscore-java17/blob/main/LICENSE)
[](https://github.com/javadev/underscore-java17/actions/workflows/maven.yml)
[](https://github.com/javadev/underscore-java17/actions/workflows/codeql.yml)
@@ -31,7 +31,7 @@ To configure your Maven project, add the following code to your pom.xml file:
com.github.javadev
underscore17
- 1.75
+ 1.76
...
@@ -40,7 +40,7 @@ To configure your Maven project, add the following code to your pom.xml file:
Gradle configuration:
```groovy
-implementation 'com.github.javadev:underscore17:1.75'
+implementation 'com.github.javadev:underscore17:1.76'
```
### Usage
diff --git a/pom-central17.xml b/pom-central17.xml
index 7566c88..c374710 100644
--- a/pom-central17.xml
+++ b/pom-central17.xml
@@ -4,7 +4,7 @@
com.github.javadev
underscore17
jar
- 1.75
+ 1.76
java 17 port of Underscore.js
The java 17 port of Underscore.js
https://github.com/javadev/underscore-java17
diff --git a/pom-central21.xml b/pom-central21.xml
index 3f305fd..4e429c4 100644
--- a/pom-central21.xml
+++ b/pom-central21.xml
@@ -4,7 +4,7 @@
com.github.javadev
underscore21
jar
- 1.75
+ 1.76
java 21 port of Underscore.js
The java 21 port of Underscore.js
https://github.com/javadev/underscore-java17
diff --git a/pom-central25.xml b/pom-central25.xml
index 8ef6297..b68ff72 100644
--- a/pom-central25.xml
+++ b/pom-central25.xml
@@ -4,7 +4,7 @@
com.github.javadev
underscore25
jar
- 1.75
+ 1.76
java 25 port of Underscore.js
The java 25 port of Underscore.js
https://github.com/javadev/underscore-java17
diff --git a/pom-pack17.xml b/pom-pack17.xml
index 6f90462..86ed022 100644
--- a/pom-pack17.xml
+++ b/pom-pack17.xml
@@ -4,7 +4,7 @@
com.github.javadev
underscore17
jar
- 1.75
+ 1.76
java 17 port of Underscore.js
The java 17 port of Underscore.js
https://github.com/javadev/underscore-java17
diff --git a/pom.xml b/pom.xml
index a77de42..463bad2 100644
--- a/pom.xml
+++ b/pom.xml
@@ -4,7 +4,7 @@
com.github.javadev
underscore17
jar
- 1.75-SNAPSHOT
+ 1.76-SNAPSHOT
java 17 port of Underscore.js
The java 17 port of Underscore.js
https://github.com/javadev/underscore-java17
diff --git a/src/main/java/com/github/underscore/U.java b/src/main/java/com/github/underscore/U.java
index b65b2ba..fb4268c 100644
--- a/src/main/java/com/github/underscore/U.java
+++ b/src/main/java/com/github/underscore/U.java
@@ -2260,7 +2260,8 @@ public static FetchResponse fetch(
}
}
- public static int readWithRetry(java.io.InputStream inputStream, byte[] buffer) throws java.io.IOException {
+ public static int readWithRetry(java.io.InputStream inputStream, byte[] buffer)
+ throws java.io.IOException {
java.io.IOException lastException = null;
for (int attempt = 0; attempt < 2; attempt++) {
try {
diff --git a/src/main/java/com/github/underscore/Xml.java b/src/main/java/com/github/underscore/Xml.java
index 732e006..793da57 100644
--- a/src/main/java/com/github/underscore/Xml.java
+++ b/src/main/java/com/github/underscore/Xml.java
@@ -1189,22 +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))) {
- 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 056c6d2..bf1fbe9 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);
@@ -1113,6 +1116,42 @@ void xmpToJson5() {
U.xmlToJson(""));
}
+ @Test
+ void xmpToJson6() {
+ assertEquals(
+ "{\n"
+ + " \"root\": {\n"
+ + " \"a\": 1\n"
+ + " },\n"
+ + " \"omit-xml-declaration\": \"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
void xmlToJsonMinimum() {
assertEquals(