Non Serializable Objects

Discussion in 'Java' started by andrewzzz, Jan 11, 2007.

  1. andrewzzz

    andrewzzz Guest

    I am working on a java project and I have to serialize a class (created
    by me) which has many references to other classes that should be
    serialized too.
    I add the marker "implements serializable" to all the necessary
    classes, but when I run I get a non serializable exception.
    Maybe one ore more objects are non serializable, but how do I identify
    them?
    I've read that If I have to serialize non serializable objects, I need
    to write my own writeObject(ObjectOutputStream out)throws IOException
    and readObject(ObjectInputStream in) , but I don't know how to
    implement and us them.
    note : I can't use transient beacuse I need everything to be
    serialized!
    Thanks a lot. Bye!
    andrewzzz, Jan 11, 2007
    #1
    1. Advertising

  2. andrewzzz

    Daniel Dyer Guest

    On Thu, 11 Jan 2007 12:37:15 -0000, andrewzzz <> wrote:

    > I am working on a java project and I have to serialize a class (created
    > by me) which has many references to other classes that should be
    > serialized too.
    > I add the marker "implements serializable" to all the necessary
    > classes, but when I run I get a non serializable exception.
    > Maybe one ore more objects are non serializable, but how do I identify
    > them?
    > I've read that If I have to serialize non serializable objects, I need
    > to write my own writeObject(ObjectOutputStream out)throws IOException
    > and readObject(ObjectInputStream in) , but I don't know how to
    > implement and us them.
    > note : I can't use transient beacuse I need everything to be
    > serialized!
    > Thanks a lot. Bye!


    Use FindBugs (http://findbugs.sourceforge.net). It's very good at
    detecting potential Serialization problems.

    Also, you may be able to make some of the problem fields static, which
    means they won't have to be serializable.

    Dan.

    --
    Daniel Dyer
    http://www.uncommons.org
    Daniel Dyer, Jan 11, 2007
    #2
    1. Advertising

  3. andrewzzz schrieb:
    > I am working on a java project and I have to serialize a class (created
    > by me) which has many references to other classes that should be
    > serialized too.
    > I add the marker "implements serializable" to all the necessary
    > classes, but when I run I get a non serializable exception.
    > Maybe one ore more objects are non serializable, but how do I identify
    > them?
    > I've read that If I have to serialize non serializable objects, I need
    > to write my own writeObject(ObjectOutputStream out)throws IOException
    > and readObject(ObjectInputStream in) , but I don't know how to
    > implement and us them.
    > note : I can't use transient beacuse I need everything to be
    > serialized!
    > Thanks a lot. Bye!
    >

    I have googled for
    readObject +writeObject +Serializable +example
    Among the first 10 links there are 3 pretty useful ones.

    --
    Thomas
    Thomas Fritsch, Jan 11, 2007
    #3
  4. andrewzzz

    Lew Guest

    andrewzzz schrieb:
    >> note : I can't use transient beacuse I need everything to be
    >> serialized!


    Totally untrue. In fact, you could [de]serialize the state if every field were
    marked transient.

    Check out Joshua Bloch's _Effective Java_. It has extremely useful chapters on
    the pitfalls and practices of serialization.

    It also has many other hot tips and tricks that will significantly advance
    your knowledge.

    - Lew
    Lew, Jan 11, 2007
    #4
    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,072
    Alvin Bruney [MVP - ASP.NET]
    May 23, 2005
  2. Dirk Daems

    jndi: non-serializable objects

    Dirk Daems, Jun 15, 2006, in forum: Java
    Replies:
    0
    Views:
    524
    Dirk Daems
    Jun 15, 2006
  3. Jimmy
    Replies:
    4
    Views:
    639
    Thomas Hawtin
    Aug 8, 2007
  4. Qu0ll
    Replies:
    8
    Views:
    1,627
    Arne Vajhøj
    Oct 12, 2008
  5. Replies:
    8
    Views:
    2,954
Loading...

Share This Page