• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Serialization of Interface Reference for an Implementation Class fails at De-serialization

 
Ranch Hand
Posts: 261
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I'll try and explain my problem as concisely and clearly as possible. I feel that what I'm trying might inherently be wrong, but somehow I believe it should work. So please feel free to treat this post as a mere clarification about the Serialization mechanism.

So, I have an Interface implemented by a class [it's implied they exist in separate files].

Now I serialize an instance of SomeImplclass:

Now in a separate project, I have a JAR of the application above which contains the interface SomeInterface, but not the implementation class SomeImpl. In this application if I try to do the following:

... I get a ClassNotFoundException [for SomeImp]. Now I know that my other project does NOT have the SomeImpl class in its classpath. But shouldn't casting into a reference of the parent interface take care of that dependency?

thanks for your inputs!
 
Sheriff
Posts: 22815
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It still needs the actual class definition (.class file).
 
Anirvan Majumdar
Ranch Hand
Posts: 261
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
so it seems.

but any suggestions as to how can one deal with a scenario where the serialised instances can be of any class adhering to a contract specified by an interface, where the de-serialiser isn't aware of which particular implementation has been used to serialise. And since the de-serialiser relies only on the contract, there's no need for it to have all available implementation classes in its classpath.
 
You're not going crazy. You're going sane in a crazy word. Find comfort in this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic