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

Discussion in 'Java' started by Will, Feb 17, 2006.

  1. Will

    Will Guest

    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?
    Will, Feb 17, 2006
    #1
    1. Advertising

  2. Re: Which objects or classes cannot be serialized? 'not serializable'error

    Will wrote:
    > 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.

    --
    John Bollinger
    John C. Bollinger, Feb 18, 2006
    #2
    1. Advertising

  3. 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.
    Paulus de Boska, Feb 18, 2006
    #3
  4. Will

    Guest

    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.
    , Feb 19, 2006
    #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.

Share This Page