This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to annotated tag 
org.apache.sling.resource.inventory-1.0.0
in repository 
https://gitbox.apache.org/repos/asf/sling-org-apache-sling-resource-inventory.git

commit 81b2fa41921a167756d1149eb52db1d24dff077b
Author: Carsten Ziegeler <[email protected]>
AuthorDate: Tue Oct 22 09:51:08 2013 +0000

    SLING-3197 : ClassCastException when serializing arrays of scalar types
    
    git-svn-id: 
https://svn.apache.org/repos/asf/sling/trunk/contrib/extensions/resource-inventory@1534576
 13f79535-47bb-0310-9956-ffa450edef68
---
 pom.xml                                            |  6 ++++++
 .../resource/inventory/impl/JsonObjectCreator.java | 23 +++++++++++++++++++++-
 2 files changed, 28 insertions(+), 1 deletion(-)

diff --git a/pom.xml b/pom.xml
index d4e5b4d..d2f9981 100644
--- a/pom.xml
+++ b/pom.xml
@@ -95,5 +95,11 @@
                <groupId>javax.servlet</groupId>
                <artifactId>servlet-api</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.apache.commons</groupId>
+            <artifactId>commons-lang3</artifactId>
+            <version>3.0</version>
+            <scope>provided</scope>
+        </dependency>
     </dependencies>
 </project>
diff --git 
a/src/main/java/org/apache/sling/resource/inventory/impl/JsonObjectCreator.java 
b/src/main/java/org/apache/sling/resource/inventory/impl/JsonObjectCreator.java
index 25984e7..bbe022b 100644
--- 
a/src/main/java/org/apache/sling/resource/inventory/impl/JsonObjectCreator.java
+++ 
b/src/main/java/org/apache/sling/resource/inventory/impl/JsonObjectCreator.java
@@ -26,6 +26,7 @@ import java.util.Iterator;
 import java.util.Locale;
 import java.util.Map;
 
+import org.apache.commons.lang3.ArrayUtils;
 import org.apache.sling.api.resource.Resource;
 import org.apache.sling.api.resource.ValueMap;
 import org.apache.sling.commons.json.JSONArray;
@@ -150,7 +151,27 @@ public abstract class JsonObjectCreator {
     throws JSONException {
         Object[] values = null;
         if (value.getClass().isArray()) {
-            values = (Object[])value;
+            if (value instanceof long[]) {
+                values = ArrayUtils.toObject((long[])value);
+            } else if (value instanceof int[]) {
+                values = ArrayUtils.toObject((int[])value);
+            } else if (value instanceof double[]) {
+                values = ArrayUtils.toObject((double[])value);
+            } else if (value instanceof byte[]) {
+                values = ArrayUtils.toObject((byte[])value);
+            } else if (value instanceof float[]) {
+                values = ArrayUtils.toObject((float[])value);
+            } else if (value instanceof short[]) {
+                values = ArrayUtils.toObject((short[])value);
+            } else if (value instanceof long[]) {
+                values = ArrayUtils.toObject((long[])value);
+            } else if (value instanceof boolean[]) {
+                values = ArrayUtils.toObject((boolean[])value);
+            } else if (value instanceof char[]) {
+                values = ArrayUtils.toObject((char[])value);
+            } else {
+                values = (Object[]) value;
+            }
             // write out empty array
             if ( values.length == 0 ) {
                 obj.put(key, new JSONArray());

-- 
To stop receiving notification emails like this one, please contact
"[email protected]" <[email protected]>.

Reply via email to