• 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

SerialVersionUID

 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic