dcsimg
Can a subclass prevent its superclass from being serialized?
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Pradeep_CK
Posted On:   Tuesday, January 8, 2002 05:56 AM

I have declared a structure called User in my idl file. The idl generator generates a file called User.java and a class called User. All data members of class User are public. class User implements serializable. Class User does not override the default serialization method because it will be overwritten every time the idl generator is run. Class UserImpl extends class User. UserImpl does not contain any data members, It exists solely to serialise the data members of User. It implements its own serialization method by implementing the Serializable interface and by having its own serialVersionUID . When a member is added to the User struct in idl, this structure is regenerated. Now, when I try to read a previously seria   More>>

I have declared a structure called User in my idl file. The idl generator generates a file called User.java and a class called User. All data members of class User are public. class User implements serializable. Class User does not override the default serialization method because it will be overwritten every time the idl generator is run.


Class UserImpl extends class User. UserImpl does not contain any data members, It exists solely to serialise the data members of User. It implements its own serialization method by implementing the Serializable interface and by having its own serialVersionUID .


When a member is added to the User struct in idl, this structure is regenerated. Now, when I try to read a previously serialised file, a java.io.InvalidCastException is thrown because the serialVersionUID of the base class has changed.


Is there any way that the sub class can prevent the base class from being serialised? Is there any other way to avoid this problem?

   <<Less

Re: Can a subclass prevent its superclass from being serialized?

Posted By:   Christopher_Schultz  
Posted On:   Tuesday, January 8, 2002 06:19 AM

I think you have three choices:




  1. Don't change your superclass.
  2. Don't read old files with new classes.
  3. Change your serialization method. You could serialize name/value pairs and ignore anything you don't recognize, or make up values for things you don't find in the file. This is most flexible, but you run the risk of getting sloppy.



-chris
About | Sitemap | Contact