Serialisation problem on customised object

Discussion in 'Java' started by ickz, May 12, 2005.

  1. ickz

    ickz Guest

    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.
     
    ickz, May 12, 2005
    #1
    1. Advertising

  2. ickz

    Esmond Pitt Guest

    ickz wrote:
    > 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?
     
    Esmond Pitt, May 13, 2005
    #2
    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. Nick Gilbert
    Replies:
    4
    Views:
    1,513
  2. Chris Meek

    Complex object Serialisation

    Chris Meek, Jan 8, 2007, in forum: ASP .Net
    Replies:
    0
    Views:
    300
    Chris Meek
    Jan 8, 2007
  3. Rotsey
    Replies:
    3
    Views:
    351
    John Saunders [MVP]
    Aug 2, 2007
  4. feng

    object serialisation

    feng, Nov 19, 2010, in forum: Java
    Replies:
    11
    Views:
    612
  5. Une bévue

    yaml object de-serialisation

    Une bévue, Feb 9, 2006, in forum: Ruby
    Replies:
    9
    Views:
    133
    David Vallner
    Feb 10, 2006
Loading...

Share This Page