Non Serializable Objects

A

andrewzzz

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!
 
D

Daniel Dyer

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

Thomas Fritsch

andrewzzz said:
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.
 
L

Lew

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
 

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,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top