This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Serializayion problem please help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Serializayion problem please help " Watch "Serializayion problem please help " New topic
Author

Serializayion problem please help

Rahul Shivsharan
Ranch Hand

Joined: Jun 17, 2009
Posts: 83
The code below has Student.java which is serializable, it also has Department's getter setter . Department.java is not serializable . But when i run the main method in EX01.java, i get Exception as Department.java is not serializable . So in Student.java i made the Department transient, now when i run the main method in Ex01.java, for Department is null while printing object Student . So i inserted writeObject and readObject method in student.java. But still i am getting Department null , please help


My Question is how to get the department values from Object Student.java when Student.java is serialized and Department.java is not serialized


The POJO below is of Student.java




the code below is Department.java



The code below is Ex01.java where main method



Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38075
    
  22
The transient keyword is intended for use for fields which can be re-entered, the classic example being a password. You don't serialise the password, but enter it again when the object is reconstructed.
If you want a reference to the department the student is in, you would have to serialise the Department object too, so I think the Department class would have to implement Serializable.
Muhammad Khojaye
Ranch Hand

Joined: Apr 12, 2009
Posts: 449

Check XStream, as this library can be use for doing Java to XML serialization for any object no matter if it is Serializable or not.


http://muhammadkhojaye.blogspot.com/
Muhammad Khojaye
Ranch Hand

Joined: Apr 12, 2009
Posts: 449

Replace line 78 of student class with and i have got department values.
Rahul Shivsharan
Ranch Hand

Joined: Jun 17, 2009
Posts: 83
Thanks mohammad , it really helped
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Serializayion problem please help
 
Similar Threads
Problem in matching property type
inputText in dataTable
Inheritance
Using Lamdaj of Google gave me an error of ClassLoader, can any body please help me
INDEX PROPERTY <html:form> with nested beans