diff --git a/conga-sling-plugin/src/main/java/io/wcm/devops/conga/plugins/sling/util/JsonOsgiConfigUtil.java b/conga-sling-plugin/src/main/java/io/wcm/devops/conga/plugins/sling/util/JsonOsgiConfigUtil.java index 25d66cf..bb01a63 100644 --- a/conga-sling-plugin/src/main/java/io/wcm/devops/conga/plugins/sling/util/JsonOsgiConfigUtil.java +++ b/conga-sling-plugin/src/main/java/io/wcm/devops/conga/plugins/sling/util/JsonOsgiConfigUtil.java @@ -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; } diff --git a/conga-sling-plugin/src/test/java/io/wcm/devops/conga/plugins/sling/util/JsonOsgiConfigUtilTest.java b/conga-sling-plugin/src/test/java/io/wcm/devops/conga/plugins/sling/util/JsonOsgiConfigUtilTest.java index 0dd51f8..3ba5384 100644 --- a/conga-sling-plugin/src/test/java/io/wcm/devops/conga/plugins/sling/util/JsonOsgiConfigUtilTest.java +++ b/conga-sling-plugin/src/test/java/io/wcm/devops/conga/plugins/sling/util/JsonOsgiConfigUtilTest.java @@ -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")); } diff --git a/conga-sling-plugin/src/test/resources/arrayTypes.json b/conga-sling-plugin/src/test/resources/arrayTypes.json index ec067f5..dc6551a 100644 --- a/conga-sling-plugin/src/test/resources/arrayTypes.json +++ b/conga-sling-plugin/src/test/resources/arrayTypes.json @@ -3,6 +3,7 @@ "intArray": [1,2,3], "boolArray": [true,false], "mixedArray": ["v1",1,true], + "emptyArray": [], "nested": { "stringArray": ["v1"] }