aspose file tools*
The moose likes I/O and Streams and the fly likes Receiving Serialized Object : Unmatched (Package) Type Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » I/O and Streams
Reply locked New topic
Author

Receiving Serialized Object : Unmatched (Package) Type

Roger F. Gay
Ranch Hand

Joined: Feb 16, 2007
Posts: 396
Problem: in.readObject() throws a ClassNotFoundException exception because it can't find the class a.package.path.CommandMessage.

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.


Correlation does not prove causality.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19722
    
  20

Double posted at http://www.coderanch.com/t/504557/sockets/java/Serialized-Object-readObject-ClassNotFoundException-path


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
Consider Paul's rocket mass heater.
 
subject: Receiving Serialized Object : Unmatched (Package) Type