1

I am facing issues with serial version id mismatch.

My server is having code with serialVersionID=20150301L; and myt client code is having diffrent so changed it manually but still facing the same issues.

Error:

java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is: java.io.InvalidClassException: com.fedex.supplies.j2ee.common.client.reqresp.CustomerDataRequest; local class incompatible: stream classdesc serialVersionUID = 20150901L, local class serialVersionUID = -955959537118369236.

I tried option like implementing serilizable,manually defined serialVersionID same as server but getting the same error each time.

Taufik Pirjade
  • 380
  • 6
  • 26
  • 1
    If you changed it manually, it wouldn't give the same error. The `local class serialVersionUID` is the number you specified. If it didn't change you didn't set it correctly and update your code. – Peter Lawrey Oct 07 '15 at 09:56
  • Can you show us how you set the `serialVersionUID` in your code? – Peter Lawrey Oct 07 '15 at 09:56
  • In other words you have to set it to what is in the stream, `20150901L`. – user207421 Oct 07 '15 at 09:56
  • AND it has to be `private static final long` – Peter Lawrey Oct 07 '15 at 09:57
  • Check your deployment strategy. Make sure you deploy the same package/classes which you use in your project. That means you should not set and compile serialVersionIDs on two different points, but only on one (and copy the compiled class e.g. in jar). – Andreas L. Oct 07 '15 at 10:10
  • @AndreasL. I am using server Jar(in which serialVersionID is speciafiled) and client code is deployed in deffrent package... – Taufik Pirjade Oct 07 '15 at 10:48
  • Do you import the class from the server jar into your client code? – Andreas L. Oct 07 '15 at 11:23
  • @TaufikPirjade You can't do that. The serialized class and the class present in deserialization have to agree in name, package, and `serialVersionUID`, *at least.* But if you had really used different packages you wouldn't have got this exception. Please clarify. – user207421 Oct 08 '15 at 08:59

1 Answers1

5

Try the following code

private static final long serialVersionUID = 20150901L;

if you don't make it private and static and final it will be ignored.

Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130
  • 1
    According to the [Object Serialization Specification](http://docs.oracle.com/javase/7/docs/platform/serialization/spec/class.html#4100) it must also be `final`. – user207421 Oct 07 '15 at 10:00
  • @EJP Thank you for the correction and the link. I have never tried to make it non-final. ;) – Peter Lawrey Oct 07 '15 at 10:01
  • I think I've made it non-`private` a few times. The spec is pretty vague about it really. – user207421 Oct 07 '15 at 10:01
  • @PeterLawrey not working for me showing same error... ;( – Taufik Pirjade Oct 07 '15 at 10:56
  • 1
    @TaufikPirjade That's not possible. You've changed the local classdesc. It can't be the same error as before, because the old error has the old local classdesc. Where would it get that from if you changed it? Are your sure you're running the new code? – user207421 Oct 07 '15 at 23:42
  • According to both the spec mentioned in the first comment and java 8 doc for [Serializable](https://docs.oracle.com/javase/8/docs/api/java/io/Serializable.html), it does not have to be private. It'll be nice, but not mandatory. – Cristian Sep 22 '20 at 17:56