• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Serializayion problem please help

 
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks mohammad , it really helped
 
If you like strawberry rhubarb pie, try blueberry rhubarb (bluebarb) pie. And try this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic