aspose file tools*
The moose likes Sockets and Internet Protocols and the fly likes SerialVersionUID Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "SerialVersionUID" Watch "SerialVersionUID" New topic
Author

SerialVersionUID

vineet kumar chaudhry
Ranch Hand

Joined: Apr 02, 2011
Posts: 45
Hi

I am sending a object through socket using serialization.The issue is

When I send it over a socket(socket.getOutputStream) and read on the server side ,it gives me java.IO.InvalidClassException.

However if I write in a file and then deserialize it in the same class, in which serialization was done,it works fine

Does this happen that sending object using socket causes errors

Even if I use to deserilaize the file which I created ,it is giving me java.IO.InvalidClassException.

I am using the same jar on the either side of socket.The difference is tthat at client side I am running thru eclipse so using jar in build path and ion server side I have kept the extracted folder from jar and placed in the current directory
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19723
    
  20

If the class files on both sides are exactly the same you shouldn't get this error. It only occurs because the class files have different serialVersionUID values. This can easily occur if you add an extra field or method. You can prevent this error in two ways:
1) make sure that both sides really do have the exact same class files.
2) define an explicit private static final long serialVersionUID. Once you've defined all the fields, you can let Eclipse generate one for you. After that you can add, remove and change methods all you want, as long as the fields stay the same.

There are also tricks to be able to handle fields that are added or removed, but you really shouldn't use instances of different versions of the class.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: SerialVersionUID