You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by Carsten Ziegeler <cz...@apache.org> on 2009/09/18 14:44:02 UTC
SLING-485: Use JSON library from json.org
We still have the bug about using the original JSON classes open
https://issues.apache.org/jira/browse/SLING-485.
In the meantime, there is a new version of the lib.
So the question is, should we update? And if we update, what does that
mean - do we just refactor the package names or do we remove these
classes completly from our version?
Carsten
--
Carsten Ziegeler
cziegeler@apache.org
Re: SLING-485: Use JSON library from json.org
Posted by Felix Meschberger <fm...@gmail.com>.
Hi,
Carsten Ziegeler schrieb:
> Felix Meschberger wrote:
>> I would love to drop our refactoring but for the sake of stability, I
>> suggest to try to upgrade to the most recent version ensureing:
>>
>> * the "keep the order fix" (meaning use LinkedHashMap for properties
>> instead HashMap IIRC)
>> * the recursion depths "fix"
>>
> Yepp, our module completly would be great, but it seems that this is out
> of question atm.
>
> The question is if we really need to upgrade to the most recent version
> of the json.org stuff? So far we don't have any problems/issues etc.
> So we could just stick to the working code and close this issue :)
+1 from me, too.
Regards
Felix
Re: SLING-485: Use JSON library from json.org
Posted by Bertrand Delacretaz <bd...@apache.org>.
On Fri, Sep 25, 2009 at 9:56 AM, Carsten Ziegeler <cz...@apache.org> wrote:
> ...The question is if we really need to upgrade to the most recent version
> of the json.org stuff? So far we don't have any problems/issues etc.
> So we could just stick to the working code and close this issue :)...
+1
-Bertrand
Re: SLING-485: Use JSON library from json.org
Posted by Alexander Klimetschek <ak...@day.com>.
Bringing this old topic back up, as I noted something in the new
json.org library that might be useful: the JSONTokener [1] now allows
for passing a Reader, and not only a String. I think this is far more
efficient, especially when you want to handle possibly larger JSON
from request bodies, eg. for SLING-1172 [2].
Also, I noticed that those sources from json.org include stuff for
mapping HTTP headers to JSON and back, same for XML. I highly doubt
that this is useful as a base json lib. Therefore an update to the
newest json org should include:
a) introducing our changes wrt order of properties (LinkedHashMap
instead of HashMap) and deep recursion
b) only keep the 7 base sources, namely JSON* with * = [Object,
String, Array, Stringer, Writer, Tokener, Exception]
Because of only 7 files, I don't think it is actually hard to
re-introduce our small changes.
[1] http://www.JSON.org/java/org/json/JSONTokener.java
[2] https://issues.apache.org/jira/browse/SLING-1172
Regards,
Alex
--
Alexander Klimetschek
alexander.klimetschek@day.com
Re: SLING-485: Use JSON library from json.org
Posted by Carsten Ziegeler <cz...@apache.org>.
Felix Meschberger wrote:
> I would love to drop our refactoring but for the sake of stability, I
> suggest to try to upgrade to the most recent version ensureing:
>
> * the "keep the order fix" (meaning use LinkedHashMap for properties
> instead HashMap IIRC)
> * the recursion depths "fix"
>
Yepp, our module completly would be great, but it seems that this is out
of question atm.
The question is if we really need to upgrade to the most recent version
of the json.org stuff? So far we don't have any problems/issues etc.
So we could just stick to the working code and close this issue :)
Carsten
--
Carsten Ziegeler
cziegeler@apache.org
Re: SLING-485: Use JSON library from json.org
Posted by Felix Meschberger <fm...@gmail.com>.
Hi,
Bertrand Delacretaz schrieb:
> On Fri, Sep 18, 2009 at 2:52 PM, Alexander Klimetschek <ak...@day.com> wrote:
>> ...Using the original lib is better than copying it's source....
>
> In theory yes, but IIRC the original doesn't satisfy our requirement
> for respecting sort order of properties. Not sure about the details,
> I'd need to dig into our archives to provide more details.
Yes, that's the single one reason, why this issue has never been
followed up upon. We need keeping the order in the JSON objects.
Now, we could say, that in the meantime, we serialize JSON directly
using a JSONWriter instead of JSONObjects ....
But still, I am not sure, how much code still depends on this
"deviation" from standard JSON and also depend on this "implementation
detail"....
I would love to drop our refactoring but for the sake of stability, I
suggest to try to upgrade to the most recent version ensureing:
* the "keep the order fix" (meaning use LinkedHashMap for properties
instead HashMap IIRC)
* the recursion depths "fix"
Regards
Felix
Re: SLING-485: Use JSON library from json.org
Posted by Josh Kennedy <jo...@meltmedia.com>.
I was also referencing the java parser that is used to load JSON node
definitions, I apologize for not being clear enough in the first post.
If you have a node property of type date and try to set it via a JSON
definition file using the Content Loader, it will throw an exception
that there is no matching property definition. That exception is only
thrown when applying properties to an nt:file, example is below. If
you apply it to an nt:unstructured with the same mixin, it falls back
to the wildcard property and is a string, not a date, in the jcr. So
as far as I can tell, and after a look over of the JSON parser, the
JSONObject's parsing doesn't create date properties as it should.
I'm wondering if I missed something, if this is by intention, or is
this a missing feature of the parser.
Example:
mixdef.cnd
[melt:development] > mix:referenceable mixin
- 'melt:testdate' (date)
test (regular file)
test.json
{
"jcr:mixinTypes": ["melt:development"],
"melt:testdate": "2001-09-11T08:46:54.172-04:00"
}
21.09.2009 11:31:25.347 *ERROR* [OsgiInstallerThread]
org.apache.sling.jcr.contentloader.internal.Loader Cannot load initial
content for bundle disease-ed-portal : no matching property definition
found for {http://www.meltmedia.com/jcr/sling/1.0}testdate
javax.jcr.nodetype.ConstraintViolationException: no matching property
definition found for {http://www.meltmedia.com/jcr/sling/1.0}testdate
On Sep 21, 2009, at 2:59 AM, Alexander Klimetschek wrote:
> On Sat, Sep 19, 2009 at 00:15, Josh Kennedy <jo...@meltmedia.com>
> wrote:
>> One thing I noticed is that neither the sling.json, nor the actual
>> json
>> library account for handling dates (ex: json.put("myDate",
>> java.util.Date)).
>> What is the preferred method for using a date type with json
>> property
>> descriptors? There are some json java implementations which will
>> serialize
>> java dates into the Date(xxx) in the json string. I haven't looked
>> through
>> the code for the json parser to see if theirs handles it properly,
>> but
>> through testing, I haven't gotten it to work with the sling json.
>
> Sling will serialize a JCR Date object (java.util.Calendar) as String
> in the (standard) Javascript/ECMA Date format, so that it can be
> easily parsed on the client side:
>
> new SimpleDateFormat("EEE MMM dd yyyy HH:mm:ss 'GMT'Z", Locale.US)
>
> Regards,
> Alex
>
> --
> Alexander Klimetschek
> alexander.klimetschek@day.com
Re: SLING-485: Use JSON library from json.org
Posted by Alexander Klimetschek <ak...@day.com>.
On Sat, Sep 19, 2009 at 00:15, Josh Kennedy <jo...@meltmedia.com> wrote:
> One thing I noticed is that neither the sling.json, nor the actual json
> library account for handling dates (ex: json.put("myDate", java.util.Date)).
> What is the preferred method for using a date type with json property
> descriptors? There are some json java implementations which will serialize
> java dates into the Date(xxx) in the json string. I haven't looked through
> the code for the json parser to see if theirs handles it properly, but
> through testing, I haven't gotten it to work with the sling json.
Sling will serialize a JCR Date object (java.util.Calendar) as String
in the (standard) Javascript/ECMA Date format, so that it can be
easily parsed on the client side:
new SimpleDateFormat("EEE MMM dd yyyy HH:mm:ss 'GMT'Z", Locale.US)
Regards,
Alex
--
Alexander Klimetschek
alexander.klimetschek@day.com
Re: SLING-485: Use JSON library from json.org
Posted by Josh Kennedy <jo...@meltmedia.com>.
One thing I noticed is that neither the sling.json, nor the actual
json library account for handling dates (ex: json.put("myDate",
java.util.Date)). What is the preferred method for using a date type
with json property descriptors? There are some json java
implementations which will serialize java dates into the Date(xxx) in
the json string. I haven't looked through the code for the json
parser to see if theirs handles it properly, but through testing, I
haven't gotten it to work with the sling json.
On Sep 18, 2009, at 6:36 AM, Peter Chiochetti wrote:
> Am 2009-09-18 15:06, schrieb Bertrand Delacretaz:
>
>> In theory yes, but IIRC the original doesn't satisfy our requirement
>> for respecting sort order of properties. Not sure about the details,
>> I'd need to dig into our archives to provide more details.
>
> In theory also, the only way of passing data in json without losing
> order is an array. Order matters for eg. jcr childnodes but does not
> matter for jcr node.properties.
>
> --
> peter
Re: SLING-485: Use JSON library from json.org
Posted by Peter Chiochetti <pc...@myzel.net>.
Am 2009-09-18 15:06, schrieb Bertrand Delacretaz:
> In theory yes, but IIRC the original doesn't satisfy our requirement
> for respecting sort order of properties. Not sure about the details,
> I'd need to dig into our archives to provide more details.
In theory also, the only way of passing data in json without losing
order is an array. Order matters for eg. jcr childnodes but does not
matter for jcr node.properties.
--
peter
Re: SLING-485: Use JSON library from json.org
Posted by Bertrand Delacretaz <bd...@gmail.com>.
On Fri, Sep 18, 2009 at 2:52 PM, Alexander Klimetschek <ak...@day.com> wrote:
> ...Using the original lib is better than copying it's source....
In theory yes, but IIRC the original doesn't satisfy our requirement
for respecting sort order of properties. Not sure about the details,
I'd need to dig into our archives to provide more details.
-Bertrand
Re: SLING-485: Use JSON library from json.org
Posted by Alexander Klimetschek <ak...@day.com>.
On Fri, Sep 18, 2009 at 14:44, Carsten Ziegeler <cz...@apache.org> wrote:
> We still have the bug about using the original JSON classes open
> https://issues.apache.org/jira/browse/SLING-485.
>
> In the meantime, there is a new version of the lib.
>
> So the question is, should we update? And if we update, what does that
> mean - do we just refactor the package names or do we remove these
> classes completly from our version?
+1 (if the maxdepth issue can be handled properly, that Felix
mentioned in the issue)
Using the original lib is better than copying it's source.
Regards,
Alex
--
Alexander Klimetschek
alexander.klimetschek@day.com