• 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

ObjectInputStream help required in handling the classNotFoundException

 
Ranch Hand
Posts: 100
Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I got to know from the ObjectOutputStream docs, that while writing the object to the file, the default serialization mechanism for an object writes the class of the object, the class signature, and the values of all non-transient and non-static fields. I have an issue where the class name has been changed after writing the object to the file and when I use the below code to read the values, its throwing a classNotFound exception. I would like to know if there is a way, I can handle this exception, i.e once it comes to the exception block, can I replace the classname in the object that is being read to the new class name and make it work ?



Any help on this is much appreciated. Thanks in Advance
 
Bartender
Posts: 3323
86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't think there is an easy solution to this. You could try one of the following:

1. Resurrect your original class so you can re-create the objects and add a method to the class (eg called toXXX) to build an object of the new class name type from the data in the object. Note if the class doesn't currently have a serialVersionUID you must generate the number using the serialver tool and set it to that number before you change the class file.
2. Get a hex editor and edit serialized file to specify the new class name or provide your own FilterInputStream that does this on the fly.
3. Extend ObjectInputStream and override the readClassDescriptor method to return the appropriate object stream class.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic