• Post Reply Bookmark Topic Watch Topic
  • New Topic

serialPersistentFields  RSS feed

 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Suppose my class def is
class box
{
private int l ;
private int w ;
.
..
}
I need to override default Serialization mechanism..by having serialPersistentFields.
In above class, is it possible to just save the l not w by using...
Could someone explain how to use serialPersistantFields in ObjectStreamField?
 
Lucy C
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure if this is exactly what you want to do, but you can save l and not w to the stream simply by making your class implement Serializable and marking w as transient. Then no value for w will be added to the stream when you serialize an object of the class, and if you use the same bytecode to deserialize the object, you'll get a default value instead (or you can provide a new one).
Alternatively you could make your class implement Externalizable (in which case no variable values are added to the stream by default) and provide a writeExternal method for it indicating what you want to add to the stream.
I'm not sure, but I think you only need to use serialPersistentFields if you're doing fairly weird customization, eg saving fields that aren't actually in the current definition of the class. There's an explanation in the Object Serialization specification here.

[This message has been edited by Lucy C (edited March 07, 2000).]
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!