sling-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alexander Klimetschek <aklim...@day.com>
Subject Re: Possible sling JSONObject bug
Date Fri, 05 Jun 2009 19:18:05 GMT
I think they are not equivalent in the strict Javascript sense, as the  
order of the properties in an object is defined (you can iterate over  
it). It is not to be seen as a pure hash map.

Regards,
Alex

--
Alexander Klimetschek @iPhone


Am 05.06.2009 um 21:00 schrieb "D. Stuart Freeman" <stuart.freeman@et.gatech.edu 
 >:

> In the example I do both a toString() comparison and an Object  
> comparison
> to show that it doesn't work.  The problem is that in the current  
> setup
> is as follows:
>
> JSONObject j = new JSONObject("{a:a, b:b}");
> JSONObject j = new JSONObject("{b:b, a:a}");
>
> There's no easy way to find out these are functionally equivalent.   
> The
> toString() methods of those objects will return them with the  
> properties
> in that order and as such will not be equal.  Calling .equals on the
> JSONObjects won't work either because it calls Object.equals which is
> false.
>
> On Fri, Jun 05, 2009 at 12:16:13PM -0500, John Crawford wrote:
>> Well in you're example you used toString() before comparing.
>>
>> Sent from my iPhone
>>
>> On Jun 5, 2009, at 12:14 PM, "D. Stuart Freeman"
>> <stuart.freeman@et.gatech.edu> wrote:
>>
>>> I just realized this is because JSONObject doesn't override equals.
>>> Maybe it should?
>>>
>>> On Fri, Jun 05, 2009 at 01:10:30PM -0400, D. Stuart Freeman wrote:
>>>> Should it hold that if we have two JSONObjects, j and k, that if
>>>> j.toString().equals(k.toString()) then j.equals(k)?  I ask because
>>>> I've
>>>> found that it's possible to create JSONObjects where that isn't the
>>>> case.
>>>> Here's a quick, minimal example I worked up:
>>>> http://pastebin.com/f12de25b9
>>>>
>>>> -- 
>>>> D. Stuart Freeman
>>>> Georgia Institute of Technology
>>>
>>>
>>>
>>> -- 
>>> D. Stuart Freeman
>>> Georgia Institute of Technology
>
> -- 
> D. Stuart Freeman
> Georgia Institute of Technology

Mime
View raw message