learner
learner

Reputation: 625

Please provide scenarios/conditions those fail during deserialization when a class & serialized object have same serialVersionUID?

Please provide scenarios/conditions those fail during deserialization when a class & serialized object have same serialVersionUID?

I'm looking scenarios like following

1) If a data type of an instance variable is changed then deserialization will fail

Could you please provide all such scenarios. I couldn't find such scenarios list anywhere in the internet.

Thanks

Upvotes: 2

Views: 566

Answers (2)

stacker
stacker

Reputation: 68962

The Exceptions thrown from readObject() give a first impression of what could happen.

http://java.sun.com/j2se/1.4.2/docs/api/java/io/ObjectInputStream.html#readObject()

  • ClassNotFoundException - Class of a serialized object cannot be found.
  • InvalidClassException - Something is wrong with a class used by serialization.
  • StreamCorruptedException - Control information in the stream is inconsistent.
  • OptionalDataException - Primitive data was found in the stream instead of objects.
  • IOException - Any of the usual Input/Output related exceptions.

Upvotes: 1

Stephen C
Stephen C

Reputation: 718826

The changes that will make deserialization fail are listed in the Java Object Serialization Specification, Section 5.6.1.

Upvotes: 4

Related Questions