By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,477 Members | 1,611 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,477 IT Pros & Developers. It's quick & easy.

serialize objects in java?

P: n/a
I basically want to be able to store and retrieve a tree structure in
greasemonkey. Unfortunately the GM_setValue and GM_getValue functions
only take string key value pairs. Is there a native javascript function
that will serialize the object so that it can be stored and retrieved
as strings?

Thanks.

Jun 30 '06 #1
Share this Question
Share on Google+
18 Replies


P: n/a
yusuf wrote on 30 jun 2006 in comp.lang.javascript:
I basically want to be able to store and retrieve a tree structure in
greasemonkey. Unfortunately the GM_setValue and GM_getValue functions
only take string key value pairs. Is there a native javascript function
that will serialize the object so that it can be stored and retrieved
as strings?


Methinks for a java question, You should ask a java NG.

Java != JavaScript.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jun 30 '06 #2

P: n/a
But greasemonkey uses javascript right, not java?


Evertjan. wrote:
yusuf wrote on 30 jun 2006 in comp.lang.javascript:
I basically want to be able to store and retrieve a tree structure in
greasemonkey. Unfortunately the GM_setValue and GM_getValue functions
only take string key value pairs. Is there a native javascript function
that will serialize the object so that it can be stored and retrieved
as strings?


Methinks for a java question, You should ask a java NG.

Java != JavaScript.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)


Jun 30 '06 #3

P: n/a
yusuf wrote on 30 jun 2006 in comp.lang.javascript:
Evertjan. wrote:
yusuf wrote on 30 jun 2006 in comp.lang.javascript:
> I basically want to be able to store and retrieve a tree structure
> in greasemonkey. Unfortunately the GM_setValue and GM_getValue
> functions only take string key value pairs. Is there a native
> javascript function that will serialize the object so that it can
> be stored and retrieved as strings?
Methinks for a java question, You should ask a java NG.

Java != JavaScript.


[please do not toppost on usenet]
But greasemonkey uses javascript right, not java?


Not according to your subject line text,
but you could have a point there, Yusuf.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jun 30 '06 #4

P: n/a
sorry, fixed the subject line. Also, what is top-post? thanks.

Evertjan. wrote:
yusuf wrote on 30 jun 2006 in comp.lang.javascript:
Evertjan. wrote:
yusuf wrote on 30 jun 2006 in comp.lang.javascript:

> I basically want to be able to store and retrieve a tree structure
> in greasemonkey. Unfortunately the GM_setValue and GM_getValue
> functions only take string key value pairs. Is there a native
> javascript function that will serialize the object so that it can
> be stored and retrieved as strings?

Methinks for a java question, You should ask a java NG.

Java != JavaScript.


[please do not toppost on usenet]
But greasemonkey uses javascript right, not java?


Not according to your subject line text,
but you could have a point there, Yusuf.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)


Jun 30 '06 #5

P: n/a
yusuf wrote on 01 jul 2006 in comp.lang.javascript:
sorry, fixed the subject line. Also, what is top-post? thanks.


Reasd the FAQ or do some research about Usenet Netiquette.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jun 30 '06 #6

P: n/a
"yusuf" <yu****@gmail.com> writes:
I basically want to be able to store and retrieve a tree structure in
greasemonkey. Unfortunately the GM_setValue and GM_getValue functions
only take string key value pairs. Is there a native javascript function
that will serialize the object so that it can be stored and retrieved
as strings?


Nothing native, no.

If you know the objects are only of certain types, you can construct
your own serializer (using eval() as deserializer).

----
function serialize(value) {
switch(typeof value) {
case "string":
return "\"" + value.replace(/(["\\])/g,"\\$1")
.replace(/[\x00-\x1f\x80-\uffff]/g, function(m) {
var s = "0000"+m.charCodeAt(0).toString(16);
return "\\u"+s.substring(s.length-4); })
+ "\"";
case "number":
case "boolean":
case "undefined":
return String(value);
case "object": case "function":
if (value == null) { return "null"; }
else if (value instanceof Array) {
var r = [];
for (var i = 0; i < value.length; i++) {
r[i] = serialize(value[i]);
}
return "[" + r.join(",") + "]";
} else if (value instanceof RegExp) {
return String(value);
} else {
var r = [];
for(i in value) {
r.push(serialize(i)+":"+serialize(value[i]));
}
return "{" + r.join(",") + "}";
}
default:
return "undefined";
}
}
----
It's not magic. If you use complex objects with constructors,
arrays with non-integer indices, or other fancy stuff, it
fails.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jun 30 '06 #7

P: n/a

Evertjan. wrote:
yusuf wrote on 01 jul 2006 in comp.lang.javascript:
sorry, fixed the subject line. Also, what is top-post? thanks.


Reasd the FAQ or do some research about Usenet Netiquette.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)


Looked it up. thanks. I guess top posting sucks if you use a crappy
client. modern ones allow the top post to be more efficient.

thanks.

Jun 30 '06 #8

P: n/a
yusuf wrote:
I basically want to be able to store and retrieve a tree structure in
greasemonkey. Unfortunately the GM_setValue and GM_getValue functions
only take string key value pairs. Is there a native javascript function
that will serialize the object so that it can be stored and retrieved
as strings?


You could be more specific... How complex is this tree structure? And especially, which of
the top 20 hits for http://www.google.com/search?q=javascript%20serializer have you tried
and in what ways don't they suit your needs?
Jun 30 '06 #9

P: n/a
yusuf wrote:
Evertjan. wrote:
yusuf wrote on 01 jul 2006 in comp.lang.javascript:

sorry, fixed the subject line. Also, what is top-post? thanks.


Reasd the FAQ or do some research about Usenet Netiquette.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

Looked it up. thanks. I guess top posting sucks if you use a crappy
client. modern ones allow the top post to be more efficient.

No they don't. Top posting is rude, end of story.

--
Ian Collins.
Jun 30 '06 #10

P: n/a

Ian Collins wrote:
yusuf wrote:
Evertjan. wrote:
yusuf wrote on 01 jul 2006 in comp.lang.javascript:
sorry, fixed the subject line. Also, what is top-post? thanks.

Reasd the FAQ or do some research about Usenet Netiquette.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

Looked it up. thanks. I guess top posting sucks if you use a crappy
client. modern ones allow the top post to be more efficient.

No they don't. Top posting is rude, end of story.

--
Ian Collins.


Thats quite a narrow minded view. I think its more tradition, rather
than anything else. I'm basing my opinion on my experiences with ease
of use of modern clients etc. I would like to know what your
experiences lead you to prefer bottom posting, because I may never have
experienced your use cases.

Jun 30 '06 #11

P: n/a

Ian Collins wrote:
yusuf wrote:
Evertjan. wrote:
yusuf wrote on 01 jul 2006 in comp.lang.javascript:
sorry, fixed the subject line. Also, what is top-post? thanks.

Reasd the FAQ or do some research about Usenet Netiquette.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

Looked it up. thanks. I guess top posting sucks if you use a crappy
client. modern ones allow the top post to be more efficient.

No they don't. Top posting is rude, end of story.

--
Ian Collins.


Thats quite a narrow minded view. I think its more tradition, rather
than anything else. I'm basing my opinion on my experiences with ease
of use of modern clients etc. I would like to know what your
experiences lead you to prefer bottom posting, because I may never have
experienced your use cases.

Jun 30 '06 #12

P: n/a
yusuf said the following on 6/30/2006 7:22 PM:
Evertjan. wrote:
yusuf wrote on 01 jul 2006 in comp.lang.javascript:
sorry, fixed the subject line. Also, what is top-post? thanks.

Reasd the FAQ or do some research about Usenet Netiquette.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)


Looked it up. thanks. I guess top posting sucks if you use a crappy
client. modern ones allow the top post to be more efficient.


Who fed you that line of crap about "modern ones"?

Besides, it has nothing to do with the newsreader, per se, it has to do
with readability and being able to follow a thread and top-posting does
*not* promote that ease - irregardless of the newsreader.

But, speaking of "modern newsreaders", most decent ones automatically
trim signatures. Maybe you need a "modern one".

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Temporarily at: http://members.aol.com/_ht_a/hikksnotathome/cljfaq/
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jul 1 '06 #13

P: n/a
yusuf said the following on 6/30/2006 7:57 PM:
Ian Collins wrote:
yusuf wrote:
Evertjan. wrote:

yusuf wrote on 01 jul 2006 in comp.lang.javascript:
> sorry, fixed the subject line. Also, what is top-post? thanks.
Reasd the FAQ or do some research about Usenet Netiquette.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

Looked it up. thanks. I guess top posting sucks if you use a crappy
client. modern ones allow the top post to be more efficient.
No they don't. Top posting is rude, end of story.

--
Ian Collins.


Thats quite a narrow minded view.


No, it's not. It is the view of perhaps 99% of the regular posters to
this group, if not 100% of them.
I think its more tradition, rather than anything else.
Wrong again. It has to do with readability.
I'm basing my opinion on my experiences with ease of use of modern
clients etc.
"modern" has nothing to do with the quality of the agent. The one you
happen to use is "modern" but it's crap. Just makes it "modern crap" is
all. I call it crap because it can't trim a signature properly.
I would like to know what your experiences lead you to prefer bottom posting,


Common sense mostly. But if you must, then it has to do with following a
thread. If I have not followed a thread but read the last post, I have
to scroll down, read the previous text, scroll back up and read what
someone replied to it. That is *not* the "most efficient" way.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Temporarily at: http://members.aol.com/_ht_a/hikksnotathome/cljfaq/
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jul 1 '06 #14

P: n/a

Randy Webb wrote:
yusuf said the following on 6/30/2006 7:57 PM:
Ian Collins wrote:
yusuf wrote:
Evertjan. wrote:

> yusuf wrote on 01 jul 2006 in comp.lang.javascript:
>
>
>> sorry, fixed the subject line. Also, what is top-post? thanks.
> Reasd the FAQ or do some research about Usenet Netiquette.
>
> --
> Evertjan.
> The Netherlands.
> (Please change the x'es to dots in my emailaddress)

Looked it up. thanks. I guess top posting sucks if you use a crappy
client. modern ones allow the top post to be more efficient.

No they don't. Top posting is rude, end of story.

--
Ian Collins.


Thats quite a narrow minded view.


No, it's not. It is the view of perhaps 99% of the regular posters to
this group, if not 100% of them.
I think its more tradition, rather than anything else.


Wrong again. It has to do with readability.
I'm basing my opinion on my experiences with ease of use of modern
clients etc.


"modern" has nothing to do with the quality of the agent. The one you
happen to use is "modern" but it's crap. Just makes it "modern crap" is
all. I call it crap because it can't trim a signature properly.
I would like to know what your experiences lead you to prefer bottom posting,


Common sense mostly. But if you must, then it has to do with following a
thread. If I have not followed a thread but read the last post, I have
to scroll down, read the previous text, scroll back up and read what
someone replied to it. That is *not* the "most efficient" way.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Temporarily at: http://members.aol.com/_ht_a/hikksnotathome/cljfaq/
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/


if your following a thread, then you are just interested in the latest
post. If not, then you want to scroll down through the last posts and
read them... but anyways, if most people are used to this, then I guess
it has the efficiency of the masses.

Jul 1 '06 #15

P: n/a
yusuf wrote:

No they don't. Top posting is rude, end of story.


Thats quite a narrow minded view. I think its more tradition, rather
than anything else.


Entering into a group and flaunting its traditions is rude.

Whether that group is a newsgroup or a club doesn't matter.

If you were to walk into a Catholic church and drink the holy water,
that would also be rude.
--
"The most convoluted explanation that fits all of the made-up facts is
the most likely to be believed by conspiracy theorists. Fitting the
actual facts is optional."
Jul 1 '06 #16

P: n/a
"yusuf" <yu****@gmail.com> writes:
Randy Webb wrote:
--
Randy

....

(included signature, see below)
if your following a thread, then you are just interested in the latest
post. If not, then you want to scroll down through the last posts and
read them...
That's because you are missing half the point on how to respond.
You should *not* include the entire previous post in your reply, but
only enough of it to give context to your reply. The ability to
read the entire previous post is already there, as every reply contains
a References: header with, at least, the previous post in the thread
of responses, and the news-server holds that message for some time
(and after that there's Google Groups).

You should also trim the signature of the previous message, unless
explicitly replying to it (and complaining about other peoples'
signatures is not a good idea, unless it accidentally happens to
be on topic :).
but anyways, if most people are used to this, then I guess
it has the efficiency of the masses.


This response style (selectiv quoting, interleaved replies) has
evolved over a *long* time. It is tailored for newsgroups, and I do
believe it is the most efficient and readable style for that.

It is *not* necessarily a good style for e-mail conversations, since
a complete history is sometimes necessary to introduce a new person
to a long conversation. For personal e-mails, that I don't expect
to see bouced around, I use interleaved style. For business e-mails,
I use top posting and full quotes. It's all about the expected usage
of the message.

And it is not rude. Not respecting that others prefer a specific style
of replies might be construed as rude, by them, but mostly it's just a
bad way to get those peoples' help.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 1 '06 #17

P: n/a
Hi,

Tony wrote:
Entering into a group and flaunting its traditions is rude.

Whether that group is a newsgroup or a club doesn't matter.

If you were to walk into a Catholic church and drink the holy water,
that would also be rude.


Absolutely. Everyone knows that it's for washing hands only!

Laurent
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
Private/Malaysia: http://mypage.bluewin.ch/lbugnion
Support children in Calcutta: http://www.calcutta-espoir.ch
Jul 1 '06 #18

P: n/a
This response style (selectiv quoting, interleaved replies) has
evolved over a *long* time. It is tailored for newsgroups, and I do
believe it is the most efficient and readable style for that.

It is *not* necessarily a good style for e-mail conversations, since
a complete history is sometimes necessary to introduce a new person
to a long conversation. For personal e-mails, that I don't expect
to see bouced around, I use interleaved style. For business e-mails,
I use top posting and full quotes. It's all about the expected usage
of the message.

And it is not rude. Not respecting that others prefer a specific style
of replies might be construed as rude, by them, but mostly it's just a
bad way to get those peoples' help.


Lasse,

Awesome reply, gets into the meat of the issue and provides good
reasons for the style. It was helpful and convincing, rather the "god,
your so rude, you suck" emails that these types of debates generate
among geeks. :)

Y

Jul 1 '06 #19

This discussion thread is closed

Replies have been disabled for this discussion.