Serialisation problem on customised object

I

ickz

I am trying to send various data via an ObjectOutputStream. Its working
fine for any ints or Strings, but when I try to write a customised
object, it appears to be not written at all - as when reading things
back in at the other side (via ObjectInputStream), an EOFException
occurs (where that customised object should be).

I've been trying to write the object using
'writeObject(myCustomisedObject);' - no errors are thrown for the
writing, it just doesn't appear to actually write it. The customised
class is serialisable and I tried adding in :

public void writeObject(ObjectOutputStream s) throws IOException {
s.defaultWriteObject();
}
public void readObject(ObjectInputStream s) throws IOException,
ClassNotFoundException {
s.defaultReadObject();
}

and tried to use those methods, but this didn't get me anywhere either.

Any hints as to what I'm doing wrong and what I need to look at? Any
help would be much appreciated, thanks.
 
E

Esmond Pitt

ickz said:
I am trying to send various data via an ObjectOutputStream. Its working
fine for any ints or Strings, but when I try to write a customised
object, it appears to be not written at all - as when reading things
back in at the other side (via ObjectInputStream), an EOFException
occurs (where that customised object should be).

I've been trying to write the object using
'writeObject(myCustomisedObject);' - no errors are thrown for the
writing, it just doesn't appear to actually write it. The customised
class is serialisable and I tried adding in :

public void writeObject(ObjectOutputStream s) throws IOException {
s.defaultWriteObject();
}
public void readObject(ObjectInputStream s) throws IOException,
ClassNotFoundException {
s.defaultReadObject();
}

and tried to use those methods, but this didn't get me anywhere either.

Any hints as to what I'm doing wrong and what I need to look at? Any
help would be much appreciated, thanks.

(a) you don't need those readObject/writeObject methods, but if you want
them, they must be private not public.

(b) You must be getting an exception when you do
writeObject(myCustomObject).

(c) are you sure that MyCustomObject is Serializable, and everything
non-transient in its object graph?
 

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,731
Messages
2,569,432
Members
44,832
Latest member
GlennSmall

Latest Threads

Top