473,385 Members | 1,766 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

serialize objects in java?

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
18 2294
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
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
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
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
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
"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

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
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
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

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

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
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
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

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
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
"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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: titanandrews | last post by:
Hi All, There is a library for Java called XStream which will serialize instances to XML. It's very easy to use and does not require changing existing code. Basically, you just call 1 API method...
14
by: vince | last post by:
Can I add (append) to an xml file that already contains a serialized object, and be able to deserialize to either or both objects from the same file...??? How is this done...?? thanks, vince
5
by: David Sworder | last post by:
Hi, I've created a UserControl-derived class called MyUserControl that is able to persist and subsequently reload its state. It exposes two methods as follows: public void Serialize(Stream...
2
by: films | last post by:
I understand the concept. Serialization of a class will add all the sub-objects of the class to the stream if there are also serializible. So say I have: class Author {
2
by: Dave | last post by:
I have an application running on a 3 server webfarm running Windows 2003 with SQLServer Session state. After running for several hours, I started getting the following error. When I access each...
1
by: js | last post by:
Does anybody knows how to solve the problem? I added attribute to the following classes in Microsoft.Practices.EnterpriseLibrary.Data namespace, but I still get the error. Thanks. ...
1
by: Tim | last post by:
Could anyone tell me what this means and how do I correct it. Any suggestions? Thanks! Tim Richardson IT Developer and Consultant www.paladin3d.com Unable to serialize the session state. In...
4
by: =?Utf-8?B?Qnlyb24=?= | last post by:
When I try to serialize an instance of the LocationCell below (note Building field) I get an error in the reflection attempt. If I remove the _Building field it serializes fine. I tried renaming...
4
by: nano2 | last post by:
Hi all , I am having a issue with importing the following import com.sun.org.apache.xml.internal.serialize.OutputFormat; import com.sun.org.apache.xml.internal.serialize.XMLSerializer; using the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.