Languages

Java - Exception in thread "main" java.io.InvalidClassException: logic.User; class invalid for deserialization

4 points
Asked by:
jonrsharpe
436

I would like to write program that deserialize object using ObjectInputStream class but it throws exception, even if ObjectOutputStream class was used to serialize object.

Exception details:

1 answer
7 points
Answered by:
Root-ssh
178180

Do you have defined static final long serialVersionUID filed at the beginning in your User class? If not, try to use some random value there.

That filed is used to identify the object, preventing against type mistakes when we serialize and deserialize object to binary.

Example:

Practical example is avaialble here.

0 commentsAdd comment
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join