Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Non Serializable Objects

Reply
Thread Tools

Non Serializable Objects

 
 
andrewzzz
Guest
Posts: n/a
 
      01-11-2007
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!

 
Reply With Quote
 
 
 
 
Daniel Dyer
Guest
Posts: n/a
 
      01-11-2007
On Thu, 11 Jan 2007 12:37:15 -0000, andrewzzz <(E-Mail Removed)> 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
 
Reply With Quote
 
 
 
 
Thomas Fritsch
Guest
Posts: n/a
 
      01-11-2007
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
 
Reply With Quote
 
Lew
Guest
Posts: n/a
 
      01-11-2007
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
FindBugs complaining about non-serializable field although everythinglooks Serializable laredotornado@zipmail.com Java 8 01-15-2012 06:18 PM
Achieving serialization of non-serializable objects Qu0ll Java 8 10-12-2008 01:34 AM
Object implements Serializable, but includes field(s) that do NOT implement Serializable Jimmy Java 4 08-08-2007 12:22 PM
jndi: non-serializable objects Dirk Daems Java 0 06-15-2006 04:45 PM
Unable to serialize the session state. Please note that non-serializable objects or MarshalByRef objects are not permitted when session state mode is 'StateServer' or 'SQLServer'. Mike Larkin ASP .Net 1 05-23-2005 12:33 PM



Advertisments