Flo,

sorry for the late reply, but Sunday mails sometimes slip through...

On 08/28/2011 03:16 AM, Flo Wohlfart wrote:
> Hi qooxdoo developers,
>
> I have a general javascript question, however it is related to qooxdoo,
> so I decided to ask it here.
>
> I am trying to send a qooxdoo object from one host to another. This
> means I want to JSON.stringify the object on the sending host, send the
> string to the recieving host and JSON.parse it to obtain an object
> again.

I'm not an expert on Json.stringify, but the (lengthy) explanation of 
the API [1] should tell you something about its limitations. 
Specifically, complex (qooxdoo) objects need to provide a .toJson() 
method to support stringification, or you must provide a "replacer" 
function when calling .stringify.

[1] http://demo.qooxdoo.org/current/apiviewer/#qx.lang.Json~stringify

> In my case I want to send an "qx.html.Element" object. However it

The qx.html.Element class doesn't seem to provide a .toJson method, so 
you have to come up with your own replacer function.

> appears, that the object is not the same after stringifying and parsing

Yes, there are some intrinsic problems. E.g. functions cannot be 
stringyfied, so you lose all method members. Also, qooxdoo objects have 
unique id's that are specific to an object instance; these cannot be 
restored on .parse, asf.

> it. I wrote an example in the playground to illustrate that:
> http://www.tinyurl.com/3s6f3pj

Oh, sorry, now I realize that you are using the native JSON object, 
rather than qx.lang.Json ... But shouldn't make a difference if used on 
browsers that have the native JSON object.

> Do you have any idea why I can not add the object again after the
> stringify and parse operations?

Well, for one reason, because the .stringify fails on your "elem" object 
in Chrome, despite the "elem.free()" call. Chrome reports "TypeError: 
Converting circular structure to JSON". Consequently, you var str 
remains undefined and JSON.parse() has nothing to build up from.

In Firefox the element is stringified, but why the parent.add() is not 
working, I don't know. Maybe others can comment better.

T.


------------------------------------------------------------------------------
Special Offer -- Download ArcSight Logger for FREE!
Finally, a world-class log management solution at an even better 
price-free! And you'll get a free "Love Thy Logs" t-shirt when you
download Logger. Secure your free ArcSight Logger TODAY!
http://p.sf.net/sfu/arcsisghtdev2dev
_______________________________________________
qooxdoo-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel

Reply via email to