[Biojava-l] serialization

Matthew Pocock mrp@sanger.ac.uk
Tue, 01 Aug 2000 11:19:31 +0100


Thanks to those of you who commented on this. The upshot is as follows:

transient fields are not serialized (as per specs).
During deserialization, transient fields are initialized with null (or
zero).
final fields are serialized/deserialized as-per any other field

final transient fields are not serialized, but can't be re-set to a usefull
value after deserialization as they are final (so you can't assign them from
null to a useful value).

The prize for the cleanest way to set transient fields was supplied by
Gerald Loeffler and goes as follows:

> hi!
>
> Just implement method
>
>         private void readObject(java.io.ObjectInputStream in) throws
> IOException, ClassNotFoundException;
>
> in the serialisable class by first calling
>
>         in.defaultReadObject();
>
> and then initialising transient fields to "useful values".
>

Matthew Pocock wrote:

> Dear all,
>
> I am confused about serialization. Some BioJava objects need to have
> transient fields. When the object is de-serialized, these fields will be
> null. Does anybody know what methods I need to provide to set up the
> transient fields to usefull values during deserialization?
>
> Thanks
>
> Matthew
>
> --
> Joon: You're out of your tree
> Sam:  It wasn't my tree
>                                                  (Benny & Joon)
>
> _______________________________________________
> Biojava-l mailing list  -  Biojava-l@biojava.org
> http://biojava.org/mailman/listinfo/biojava-l

--
Joon: You're out of your tree
Sam:  It wasn't my tree
                                                 (Benny & Joon)