Serializing a HashMap

T

Tricia Williams

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

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
 
T

Thomas Hawtin

Tricia said:
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
 
R

Roedy Green

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top