Which objects or classes cannot be serialized? 'not serializable' error

W

Will

I have a 'not serializable error' on sessions in a srevr cluster
problem
(the clustered servers are sharing session data and whinge that some
of it cannot be serialized, - I have to solve this problem somehow)
and want to find a list of classes that cannot be serialized so
I can find out just what is not serializing in my clustered session
data.
Its a negative, so not easy to search - I know I could look at every
java
class to see if its serializable but that would take 3 years hard work.


Is there a common list somewhere or some overriding simple principle
that
would tell me that something is probably not serializable?
 
J

John C. Bollinger

Will said:
I have a 'not serializable error' on sessions in a srevr cluster
problem
(the clustered servers are sharing session data and whinge that some
of it cannot be serialized, - I have to solve this problem somehow)
[...]

Is there a common list somewhere or some overriding simple principle
that
would tell me that something is probably not serializable?

Sure. If it's a Java object, then it's probably not Serializable.
Really. Serializability is the exception, not the rule.

More practically, no object can be serialized (via Java's built-in
mechanism) unless its class implements the Serializable interface.
Being an instance of such a class is not a sufficient condition,
however: for an object to be successfully serialized, it must also be
true that all non-transient references it holds must be null or refer to
serializable objects. (Do note that that is a recursive condition.)
Primitive values, nulls, and transient variables aren't a problem.
Static variables do not belong to individual objects, so they don't
present a problem either.

Some common classes are reliably serialization-safe. Strings are
probably most notable here, but all the wrapper classes for primitive
types are also safe. Arrays of primitives are reliably serializable.
Arrays of reference types can be serialized if all their elements can be
serialized.
 
P

Paulus de Boska

The index of the Java Developers Almanac shows you the classes that
implement Serializable. You could also write a program to scan the
documentation files for 'implements Serializable' and then some.
 
B

billreyn

Thanks for the info about serializable objects, I
am going to scan my error log now to find out
just which session data objects never made it
across the network on my app server.
I hope that this non-serializable session data
(in a cluster) is not important and I can 'transient'
it.
 

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

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top