• Post Reply Bookmark Topic Watch Topic
  • New Topic

Serialized Object : readObject() ClassNotFoundException (path difference)

 
Roger F. Gay
Ranch Hand
Posts: 408
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Problem: in.readObject() throws a ClassNotFoundException exception because it can't find the class a.package.path.CommandMessage.

(Sorry about the double-posting. I posted this to I/O and Streams, then looking at the discussion here, it seemed even reasonabler to post here.)

I'm sending a serialized object via socket; using writeObject(), readObject(). There are now two versions of the same system that are communicating with one another; one prototype version in which no packages were defined, and a newer version in which classes have been moved into packages.

I am sending a java object (class name: CommandMessage) from the new version with packages to the old version without. The class is defined the same way in both versions, except for the package path.

In other words:
NewSystem: out.writeObject(a.package.path.CommandMessage commandMessage) -> OldSystem: CommandMessage commandMessage = in.readObject() in a system where CommandMessage is in an unnamed package (no package defined).

in.readObj() throws a ClassNotFoundException exception because it can't find the class a.package.path.CommandMessage.

If there's some way to beat this problem, I'd certainly like to know. I'm preparing to Open Source the system. It's a young system and maybe things will be shifted around into new and different packages from time to time for a while.
 
Rob Spoor
Sheriff
Posts: 20817
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Next time don't open a second thread but instead ask one of the staff to move the thread.
 
Roger F. Gay
Ranch Hand
Posts: 408
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Prime wrote:Next time don't open a second thread but instead ask one of the staff to move the thread.


Thanks. I did not know that.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!