File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Serializayion problem please help

 
Rahul Shivsharan
Ranch Hand
Posts: 83
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 47300
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 449
IntelliJ IDE Java Scala
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Muhammad Khojaye
Ranch Hand
Posts: 449
IntelliJ IDE Java Scala
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Replace line 78 of student class with and i have got department values.
 
Rahul Shivsharan
Ranch Hand
Posts: 83
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks mohammad , it really helped
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic