Win a copy of JDBC Workbook this week in the JDBC and Relational Databases forum
or A Day in Code in the A Day in Code forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

Serializayion problem please help

 
Ranch Hand
Posts: 83
  • 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



 
Marshal
Posts: 69399
276
  • 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.
 
Ranch Hand
Posts: 449
Scala IntelliJ IDE Java
  • 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
Scala IntelliJ IDE Java
  • 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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks mohammad , it really helped
 
Live a little! The night is young! And we have umbrellas in our drinks! This umbrella has a tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic