Serializing a HashMap

Discussion in 'Java' started by Tricia Williams, Sep 20, 2005.

  1. Hi All,

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

    Thanks,
    Tricia
     
    Tricia Williams, Sep 20, 2005
    #1
    1. Advertising

  2. 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
     
    =?ISO-8859-1?Q?Karl_=D8ie?=, Sep 20, 2005
    #2
    1. Advertising

  3. Tricia Williams

    Guest

    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/
     
    , Sep 20, 2005
    #3
  4. 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/
     
    Thomas Hawtin, Sep 20, 2005
    #4
  5. Tricia Williams

    Roedy Green Guest

    On Tue, 20 Sep 2005 10:52:36 -0400, Tricia Williams
    <> 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, Sep 20, 2005
    #5
  6. Tricia Williams

    Roedy Green Guest

    On Tue, 20 Sep 2005 10:52:36 -0400, Tricia Williams
    <> 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.
     
    Roedy Green, Sep 20, 2005
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Aidan Glendye

    Serializing classes derived from dataset

    Aidan Glendye, Jul 28, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    500
    Aidan Glendye
    Jul 28, 2003
  2. Jason Shohet
    Replies:
    4
    Views:
    358
    bruce barker
    Jul 29, 2003
  3. Vince Darley
    Replies:
    4
    Views:
    4,429
    emilchacko
    Mar 2, 2010
  4. Replies:
    3
    Views:
    6,483
  5. Rakesh
    Replies:
    10
    Views:
    12,182
    Mike Schilling
    Apr 8, 2008
Loading...

Share This Page