Forums > Java

find a non-serializable class/object


jbm
January 6, 2008 | 9:29 pm

I’m wondering if there’s any way of tracking down the specific object that’s causing a NotSerializableException? I have a fairly complex object that I’m trying to write to disk, and I keep getting this exception. I’ve checked all of my class files, and they all implement Serializable. If I could at least find out which object is failing, maybe I could figure out what’s wrong.

Any thoughts appreciated.

thanks,

J.


January 6, 2008 | 9:36 pm

Doesn’t it say in the stack trace?


O

jbmaxwell wrote:
> I’m wondering if there’s any way of tracking down the specific object
> that’s causing a NotSerializableException? I have a fairly complex
> object that I’m trying to write to disk, and I keep getting this
> exception. I’ve checked all of my class files, and they all implement
> Serializable. If I could at least find out which object is failing,
> maybe I could figure out what’s wrong.
>
> Any thoughts appreciated.
>
> thanks,
>
> J. _______________________________________________ java-dev mailing
>



jbm
January 6, 2008 | 10:01 pm

No. All it shows in the trace, before it hits my "save" method is:

java.io.NotSerializableException: java.lang.Object
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1081)
at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1375)
at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1347)
at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1290)
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1079)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:302)

…which doesn’t do me much good.

J.

Quote: owen wrote on Sun, 06 January 2008 21:36
—————————————————-
> Doesn’t it say in the stack trace?
>
> –
> O
>
> jbmaxwell wrote:
> > I’m wondering if there’s any way of tracking down the specific object
> > that’s causing a NotSerializableException? I have a fairly complex
> > object that I’m trying to write to disk, and I keep getting this
> > exception. I’ve checked all of my class files, and they all implement
> > Serializable. If I could at least find out which object is failing,
> > maybe I could figure out what’s wrong.
> >
> > Any thoughts appreciated.
> >
> > thanks,
> >
> > J. _______________________________________________ java-dev mailing
> >
>
>
>
—————————————————-


January 9, 2008 | 7:48 pm

> java.io.NotSerializableException: java.lang.Object

Suggests that it’s choking on trying to serialize an instance of
java.lang.Object. This seems unlikely, but it’s possible that a class
somewhere in your object graph has a field declared as Object.

This could include built-in classes (like implementations of Reference,
for example). If you can find it, you could either skip serializing it,
by also declaring it transient, or work out way of serializing the thing.

Eclipse, or similar, should make it much easier to find the culprit, if
you’re not already using it.


O

jbmaxwell wrote:
> No. All it shows in the trace, before it hits my "save" method is:
>
> java.io.NotSerializableException: java.lang.Object
> at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1081)
> at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1375)
> at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1347)
> at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1290)
> at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1079)
> at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:302)
>
> …which doesn’t do me much good.
>
> J.
>
>
>



jbm
January 9, 2008 | 8:10 pm

Cheers, Owen.

Yes, I’m using Eclipse already. I’ll look for a generic Object. I’m not sure where that would be, but I do have some vague recollection that I might have used an ArrayList to handle some subclassed objects… Not sure. Maybe that’s where it’s choking. I’ll look into it.

I read somewhere that serialization is not great for persistence. But that’s about all I’ve been using, so far. Any particular approaches I should read up on? What do you tend to use?

thanks again.

J.

Quote: owen wrote on Wed, 09 January 2008 19:48
—————————————————-
>
> > java.io.NotSerializableException: java.lang.Object
>
> Suggests that it’s choking on trying to serialize an instance of
> java.lang.Object. This seems unlikely, but it’s possible that a class
> somewhere in your object graph has a field declared as Object.
>
> This could include built-in classes (like implementations of Reference,
> for example). If you can find it, you could either skip serializing it,
> by also declaring it transient, or work out way of serializing the thing.
>
> Eclipse, or similar, should make it much easier to find the culprit, if
> you’re not already using it.
>
> —
> O
>
> jbmaxwell wrote:
> > No. All it shows in the trace, before it hits my "save" method is:
> >
> > java.io.NotSerializableException: java.lang.Object
> > at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1081)
> > at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1375)
> > at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1347)
> > at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1290)
> > at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1079)
> > at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:302)
> >
> > …which doesn’t do me much good.
> >
> > J.
> >
> >
> >
>
>
—————————————————-


Viewing 5 posts - 1 through 5 (of 5 total)