You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by Christophe Lombart <ch...@gmail.com> on 2009/08/11 10:56:47 UTC

JsonQueryServlet output

Hi all,
I'm using the JsonQueryServlet to retrieve content and some properties.
Everything works fine excepted for Calendar props. The output format for
Calendar is not correct.
I'm just wondering if it is not better to convert properties based on
calendar with a DateFormater (similar to the implementation of
JsonRendererServlet/JsonResourceWriter) ?


br,
Christophe

Re: JsonQueryServlet output

Posted by Christophe Lombart <ch...@gmail.com>.
My intention was also  to provide a patch with the JsonResourceWriter (if
possible).I'm going  work on that.

Christophe


2009/8/12 Bertrand Delacretaz <bd...@apache.org>

> Hi Christophe,
>
> On Tue, Aug 11, 2009 at 10:56 AM, Christophe
> Lombart<ch...@gmail.com> wrote:
> > ...I'm using the JsonQueryServlet to retrieve content and some
> properties.
> > Everything works fine excepted for Calendar props. The output format for
> > Calendar is not correct.
> > I'm just wondering if it is not better to convert properties based on
> > calendar with a DateFormater (similar to the implementation of
> > JsonRendererServlet/JsonResourceWriter) ?...
>
> Sure, good idea.
>
> The patch below shows where to make the changes, or maybe it would be
> better to use the JsonResourceWriter for this rendering anyway? I
> havent investigated the impact of this latter option - in any case,
> the format of the json result set shouldn't change except for this
> improvement, I think.
>
> Tests can be added to the JsonQueryServletTest in the launchpad/testing
> module.
>
> -Bertrand
>
>
> Index:
> bundles/servlets/get/src/main/java/org/apache/sling/servlets/get/impl/JsonQueryServlet.java
> ===================================================================
> ---
> bundles/servlets/get/src/main/java/org/apache/sling/servlets/get/impl/JsonQueryServlet.java
> (revision 803418)
> +++
> bundles/servlets/get/src/main/java/org/apache/sling/servlets/get/impl/JsonQueryServlet.java
> (working copy)
> @@ -22,6 +22,7 @@
>  import java.io.InputStream;
>  import java.lang.reflect.Array;
>  import java.util.ArrayList;
> +import java.util.Calendar;
>  import java.util.Iterator;
>  import java.util.List;
>  import java.util.Map;
> @@ -225,6 +226,8 @@
>                 ((InputStream) value).close();
>             } catch (IOException ignore) {
>             }
> +        } else if(value instanceof Calendar) {
> +               strValue = ((Calendar)value).getTime().toString();
>         } else if (value != null) {
>             strValue = value.toString();
>         } else {
>

Re: JsonQueryServlet output

Posted by Bertrand Delacretaz <bd...@apache.org>.
Hi Christophe,

On Tue, Aug 11, 2009 at 10:56 AM, Christophe
Lombart<ch...@gmail.com> wrote:
> ...I'm using the JsonQueryServlet to retrieve content and some properties.
> Everything works fine excepted for Calendar props. The output format for
> Calendar is not correct.
> I'm just wondering if it is not better to convert properties based on
> calendar with a DateFormater (similar to the implementation of
> JsonRendererServlet/JsonResourceWriter) ?...

Sure, good idea.

The patch below shows where to make the changes, or maybe it would be
better to use the JsonResourceWriter for this rendering anyway? I
havent investigated the impact of this latter option - in any case,
the format of the json result set shouldn't change except for this
improvement, I think.

Tests can be added to the JsonQueryServletTest in the launchpad/testing module.

-Bertrand


Index: bundles/servlets/get/src/main/java/org/apache/sling/servlets/get/impl/JsonQueryServlet.java
===================================================================
--- bundles/servlets/get/src/main/java/org/apache/sling/servlets/get/impl/JsonQueryServlet.java
(revision 803418)
+++ bundles/servlets/get/src/main/java/org/apache/sling/servlets/get/impl/JsonQueryServlet.java
(working copy)
@@ -22,6 +22,7 @@
 import java.io.InputStream;
 import java.lang.reflect.Array;
 import java.util.ArrayList;
+import java.util.Calendar;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
@@ -225,6 +226,8 @@
                 ((InputStream) value).close();
             } catch (IOException ignore) {
             }
+        } else if(value instanceof Calendar) {
+               strValue = ((Calendar)value).getTime().toString();
         } else if (value != null) {
             strValue = value.toString();
         } else {