You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by fm...@apache.org on 2010/01/26 22:31:16 UTC

svn commit: r903426 - /sling/trunk/bundles/servlets/get/src/main/java/org/apache/sling/servlets/get/impl/helpers/JsonResourceWriter.java

Author: fmeschbe
Date: Tue Jan 26 21:31:15 2010
New Revision: 903426

URL: http://svn.apache.org/viewvc?rev=903426&view=rev
Log:
SLING-1329 Try String[] if String adapter does not exist, as is the case for JcrPropertyResource wrapping a multi-value property

Modified:
    sling/trunk/bundles/servlets/get/src/main/java/org/apache/sling/servlets/get/impl/helpers/JsonResourceWriter.java

Modified: sling/trunk/bundles/servlets/get/src/main/java/org/apache/sling/servlets/get/impl/helpers/JsonResourceWriter.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/servlets/get/src/main/java/org/apache/sling/servlets/get/impl/helpers/JsonResourceWriter.java?rev=903426&r1=903425&r2=903426&view=diff
==============================================================================
--- sling/trunk/bundles/servlets/get/src/main/java/org/apache/sling/servlets/get/impl/helpers/JsonResourceWriter.java (original)
+++ sling/trunk/bundles/servlets/get/src/main/java/org/apache/sling/servlets/get/impl/helpers/JsonResourceWriter.java Tue Jan 26 21:31:15 2010
@@ -21,6 +21,7 @@
 import java.io.Writer;
 import java.text.DateFormat;
 import java.text.SimpleDateFormat;
+import java.util.Arrays;
 import java.util.Calendar;
 import java.util.Iterator;
 import java.util.List;
@@ -31,6 +32,7 @@
 import org.apache.sling.api.resource.Resource;
 import org.apache.sling.api.resource.ResourceUtil;
 import org.apache.sling.api.resource.ValueMap;
+import org.apache.sling.commons.json.JSONArray;
 import org.apache.sling.commons.json.JSONException;
 import org.apache.sling.commons.json.io.JSONWriter;
 
@@ -102,8 +104,20 @@
             // no map available, try string
             final String value = resource.adaptTo(String.class);
             if (value != null) {
+
+                // single value property or just plain String resource or...
                 w.key(ResourceUtil.getName(resource));
                 w.value(value);
+
+            } else {
+
+                // Try multi-value "property"
+                final String[] values = resource.adaptTo(String[].class);
+                if (values != null) {
+                    w.key(ResourceUtil.getName(resource));
+                    w.value(new JSONArray(Arrays.asList(values)));
+                }
+
             }
 
         } else {