Serializable question

B

ByteCoder

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,
 
S

Stefan Schulz

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.
 
G

Gordon Beaton

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
 

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

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,900
Latest member
Nell636132

Latest Threads

Top