Serializable question

Discussion in 'Java' started by ByteCoder, Dec 27, 2004.

  1. ByteCoder

    ByteCoder Guest

    I want to send a HashMap with the ObjectOutputStream. This serializes
    the HashMap.

    The HashMap will contain String keys and Custom made Objects (a
    self-made class) as a value.

    Do my own-made objects need to be serializable, or is this even possible?

    TIA,
    --
    -------------
    - ByteCoder - ...I see stupid people
    -------------
    Curiosity *Skilled* the cat
    ByteCoder, Dec 27, 2004
    #1
    1. Advertising

  2. On Mon, 27 Dec 2004 11:32:15 +0100
    ByteCoder <ByteCoder@127.0.0.1> wrote:

    > I want to send a HashMap with the ObjectOutputStream. This serializes
    > the HashMap.
    >
    > The HashMap will contain String keys and Custom made Objects (a
    > self-made class) as a value.
    >
    > Do my own-made objects need to be serializable, or is this even
    > possible?


    They will need to be Serializable, otherwise, how would the HashMap ever
    know how to "put them on the Wire" and reassemble them on the other end?

    Once this is made sure, there is no reason not to transmit a HashMap.

    --
    In pioneer days they used oxen for heavy pulling, and when one ox
    couldn't budge a log, they didn't try to grow a larger ox. We shouldn't
    be trying for bigger computers, but for more systems of computers.
    --- Rear Admiral Grace Murray Hopper
    Stefan Schulz, Dec 27, 2004
    #2
    1. Advertising

  3. On Mon, 27 Dec 2004 11:32:15 +0100, ByteCoder wrote:
    > I want to send a HashMap with the ObjectOutputStream. This
    > serializes the HashMap.
    >
    > The HashMap will contain String keys and Custom made Objects (a
    > self-made class) as a value.
    >
    > Do my own-made objects need to be serializable, or is this even
    > possible?


    The entire contents of the HashMap must be serializable, or you will
    get an exception when you attempt to write it to the
    ObjectOutputStream.

    If your keys or objects contain components that aren't serializable
    (or that you don't want serialized), declare them transient.

    /gordon

    --
    [ do not email me copies of your followups ]
    g o r d o n + n e w s @ b a l d e r 1 3 . s e
    Gordon Beaton, Dec 27, 2004
    #3
    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. Mike Larkin
    Replies:
    1
    Views:
    6,075
    Alvin Bruney [MVP - ASP.NET]
    May 23, 2005
  2. Christian
    Replies:
    1
    Views:
    463
    Gary Varga
    Jul 18, 2003
  3. Rhino

    Question re serializable

    Rhino, Dec 11, 2005, in forum: Java
    Replies:
    17
    Views:
    719
    Mike Schilling
    Dec 12, 2005
  4. Jimmy
    Replies:
    4
    Views:
    641
    Thomas Hawtin
    Aug 8, 2007
  5. Replies:
    8
    Views:
    2,976
Loading...

Share This Page