Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Java (http://www.velocityreviews.com/forums/f30-java.html)
-   -   Serializing a HashMap (http://www.velocityreviews.com/forums/t146331-serializing-a-hashmap.html)

Tricia Williams 09-20-2005 02:52 PM

Serializing a HashMap
 
Hi All,

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

Thanks,
Tricia

=?ISO-8859-1?Q?Karl_=D8ie?= 09-20-2005 03:25 PM

Re: Serializing a HashMap
 
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


iksrazal@terra.com.br 09-20-2005 04:43 PM

Re: Serializing a HashMap
 
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/


Thomas Hawtin 09-20-2005 04:48 PM

Re: Serializing a HashMap
 
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/

Roedy Green 09-20-2005 05:12 PM

Re: Serializing a HashMap
 
On Tue, 20 Sep 2005 10:52:36 -0400, Tricia Williams
<pgwillia@student.cs.uwaterloo.ca> 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.

Roedy Green 09-20-2005 05:14 PM

Re: Serializing a HashMap
 
On Tue, 20 Sep 2005 10:52:36 -0400, Tricia Williams
<pgwillia@student.cs.uwaterloo.ca> 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.


All times are GMT. The time now is 04:53 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.