Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Serializing a HashMap

Reply
Thread Tools

Serializing a HashMap

 
 
Tricia Williams
Guest
Posts: n/a
 
      09-20-2005
Hi All,

Hopefully someone can point me in the right direction. Is there anyway
to store a serialized Hashmap as a String?

Thanks,
Tricia
 
Reply With Quote
 
 
 
 
=?ISO-8859-1?Q?Karl_=D8ie?=
Guest
Posts: n/a
 
      09-20-2005
Yes maps are serializable (toString()) but that doesn't mean that the
objects in the map are serializable as strings. Storing javaobjects in
Strings are not advicable. If the final destination for the
serialization is a database or a file use the serializable keyword and
write the objects as bytearrays.

Karl Řie


Tricia Williams wrote:

> Hi All,
>
> Hopefully someone can point me in the right direction. Is there anyway
> to store a serialized Hashmap as a String?
>
> Thanks,
> Tricia

 
Reply With Quote
 
 
 
 
iksrazal@terra.com.br
Guest
Posts: n/a
 
      09-20-2005
You can store a HashMap, as long as the objects inside them implement
serializable, into any LDAP (openldap for example) that supports
java.schema .

HTH,
iksrazal
http://www.braziloutsource.com/

 
Reply With Quote
 
Thomas Hawtin
Guest
Posts: n/a
 
      09-20-2005
Tricia Williams wrote:
>
> Hopefully someone can point me in the right direction. Is there anyway
> to store a serialized Hashmap as a String?


Serialise into a ByteArrayOuputStream, then pack each pair of bytes into
a char or encode with, say, Base64.

I question why you would want to do this. If you are thinking of
embedding it in an HTML page, remember that anyone using your site can
have a look at it, recognise what it is, and send back something malicious.

Tom Hawtin
--
Unemployed English Java programmer
http://jroller.com/page/tackline/
 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      09-20-2005
On Tue, 20 Sep 2005 10:52:36 -0400, Tricia Williams
<(E-Mail Removed)> wrote or quoted :

> Hopefully someone can point me in the right direction. Is there anyway
>to store a serialized Hashmap as a String?


How about a array of bytes? See
http://mindprod.com/applets/fileio.html

Tell it you want to write a serialised object to a Byte array.

If you really really want String, try armouring it with base64 or
base64u. See http://mindprod.com/jgloss/armouring.html

don't use encodings. They won't be 100% reversible.
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.
 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      09-20-2005
On Tue, 20 Sep 2005 10:52:36 -0400, Tricia Williams
<(E-Mail Removed)> wrote or quoted :

> Hopefully someone can point me in the right direction. Is there anyway
>to store a serialized Hashmap as a String?


Perhaps what you are really trying to do is serialise to XML. In that
case just enumerate the key/value pairs and write them out wrapped in
XML tags.

--
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
reuse HashMap$Entry (or HashMap in total) to avoid millions of allocations Vince Darley Java 4 03-02-2010 07:48 AM
java.util.Properties extending from HashMap<Object, Object> insteadof HashMap<String, String> Rakesh Java 10 04-08-2008 04:22 AM
help with serializing a HashMap Aryeh.Friedman@gmail.com Java 3 11-17-2005 11:50 PM
serializing a class & performance -- advice? Jason Shohet ASP .Net 4 07-29-2003 06:47 PM
Serializing classes derived from dataset Aidan Glendye ASP .Net 1 07-28-2003 02:29 PM



Advertisments