Skip to main content
cquser1
Level 7
Apr 5, 2017 12:00 PM UTC
Solved

Usage of serialVersionUID in custom servlets which extends SlingSafeMethodsServlet

Hi All,

I have seen in multiple instances wherein serialVersionUID is assigned some random Long value in custom servlet. I am not sure as to why exactly is this used. Don't see this variable getting used anywhere.

Can someone please let me know as to what purpose does it serve.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
daniel_henriqu1
daniel_henriqu1Accepted solution
Level 4
Apr 5, 2017 2:52 PM UTC

Hi,

serialVersionUID is a Java "thing" for Serializable classes: Stream Unique Identifiers.
It's used by the regular Java serialization mechanism: Serializable Objects.

Regarding the "random" long value it has probably been generated/assigned by an IDE (Eclipse, IntelliJ), based on the characteristics of the corresponding class.

Some additional references about Servlets and serialization:

  1. Why does HttpServlet implement Serializable?
  2. Why do GenericServlet and HttpServlet implement the Serializable interface?

Best regards,

Daniel.

5 replies

daniel_henriqu1
Level 4
Apr 5, 2017 1:39 PM UTC

Hi.

serialVersionUID is a Java "thing" for Serializable classes: Stream Unique Identifiers.
It's used by the regular Java serialization mechanism: Serializable Objects.

Regarding the "random" long value, it has probably been generated/assigned by an IDE (Eclipse, IntelliJ), based on the characteristics of the corresponding class.

Some additional references about Servlets and serialization:

Best regards,

Daniel.

Translate
daniel_henriqu1
daniel_henriqu1Accepted solution
Level 4
Apr 5, 2017 2:52 PM UTC

Hi,

serialVersionUID is a Java "thing" for Serializable classes: Stream Unique Identifiers.
It's used by the regular Java serialization mechanism: Serializable Objects.

Regarding the "random" long value it has probably been generated/assigned by an IDE (Eclipse, IntelliJ), based on the characteristics of the corresponding class.

Some additional references about Servlets and serialization:

  1. Why does HttpServlet implement Serializable?
  2. Why do GenericServlet and HttpServlet implement the Serializable interface?

Best regards,

Daniel.

Translate
smacdonald2008
Level 10
Apr 5, 2017 3:19 PM UTC
cquser1
cquser1Author
Level 7
Apr 6, 2017 10:08 AM UTC

Thanks a lot Scott and Daniel for your replies.

Translate