GeeCON Prague 2014*
The moose likes I/O and Streams and the fly likes Serializing protected variable from super class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Serializing protected variable from super class" Watch "Serializing protected variable from super class" New topic
Author

Serializing protected variable from super class

A Ridolfi
Greenhorn

Joined: Nov 25, 2007
Posts: 10
Hello,

I have these classes

class javax.mail.URLName{ //does not implement serializable
protected String fullUrl; //won't serialize because class is not serializable
}

I need to serialize URLName, in particular the fullUrl field. However, I am subclassing it, and the subclass DOES implement serializable.

class URL extends javax.mail.URLName implements java.io.Serializable{}

My question is: When I serialize URL (sub-class of URLName), will the inherited fullUrl field be serializable also? Are public/default/protected inherited fields automatically serialized even though the super class don't implement Serializable?

Thank you
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19697
    
  20

You can use the readObject and writeObject methods for these:

These two methods need to work together perfectly - readObject needs to read the same type of objects as writeObject is writing, otherwise you will run into problems.

Don't worry about these methods being private, the JVM will have no problem finding these.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
A Ridolfi
Greenhorn

Joined: Nov 25, 2007
Posts: 10
Thanks for the help mate!
 
GeeCON Prague 2014
 
subject: Serializing protected variable from super class