Java - Google App Engine - InvalidClassException when changing a class that was saved in the session scope

I updated my User class, and now, when someone who had an old version of the User class stored in the access session area is accessing my site, I get an InvalidClassException .

 javax.servlet.ServletException: java.lang.RuntimeException: java.io.InvalidClassException: User; local class incompatible: stream classdesc serialVersionUID = 4949038118012519093, local class serialVersionUID = -971500502189813151 

How to stop this error for these users? I could probably cancel all sessions every time I want to update a class that is stored in the session area, but is there a better way to prevent my user from logging in again?

+4
source share
1 answer

You can add

 private final long serialVersionUID=4949038118012519093; 

to the definition of your class. The new class should have the same serializable fields in the same order, of course.

+1
source

Source: https://habr.com/ru/post/1306330/


All Articles