Skip to content

Commit

Permalink
handle empty array
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanseifert committed Jan 10, 2024
1 parent 85eb82c commit c645502
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,18 @@ else if (value instanceof Map) {
private static Class<?> detectArrayType(Collection<?> list) {
Class<?> type = null;
for (Object item : list) {
if (type == null) {
type = item.getClass();
}
else if (type != item.getClass()) {
type = Object.class;
if (item != null) {
if (type == null) {
type = item.getClass();
}
else if (type != item.getClass()) {
type = Object.class;
}
}
}
if (type == null) {
type = Object.class;
}
return type;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ void testListToArrayConversion() throws IOException {
assertArrayEquals(new Integer[] { 1, 2, 3 }, (Integer[])content.get("intArray"));
assertArrayEquals(new Boolean[] { true, false }, (Boolean[])content.get("boolArray"));
assertArrayEquals(new Object[] { "v1", 1, true }, (Object[])content.get("mixedArray"));
assertArrayEquals(new Object[0], (Object[])content.get("emptyArray"));
assertArrayEquals(new String[] { "v1" }, (String[])((Map)content.get("nested")).get("stringArray"));
}

Expand Down
1 change: 1 addition & 0 deletions conga-sling-plugin/src/test/resources/arrayTypes.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"intArray": [1,2,3],
"boolArray": [true,false],
"mixedArray": ["v1",1,true],
"emptyArray": [],
"nested": {
"stringArray": ["v1"]
}
Expand Down

0 comments on commit c645502

Please sign in to comment.