Skip to content

Files

Latest commit

 

History

History
51 lines (39 loc) · 2.4 KB

2012-12-25-intellij-idea-how-to-generate-serialversionuid.md

File metadata and controls

51 lines (39 loc) · 2.4 KB
layout title description author image tags sitemap
post
IntelliJ IDEA: How to generate ‘serialVersionUID’
It is strongly recommended that all serializable classes explicitly declare serialVersionUID values
name url
NetLicensing
url hide
/img/blog/labs64-blog-howto-idea002.png
true
Java
Howto
IDE
IntelliJ IDEA
JavaEE
Serializable
serialVersionUID
images
/img/blog/labs64-blog-howto-idea001.png
/img/blog/labs64-blog-howto-idea002.png
/img/blog/labs64-blog-howto-idea003.png

{% include advert.html image='/img/ads/netlicensing-affiliates-970x250.png' %}

When Java class implements Serializable interface you have the following options:

  • don’t declare serialVersionUID explicitly
  • add default serialVersionUID(1L)
  • generate serialVersionUID value

IntelliJ IDEA - serialVersionUID{:class="blog-center"}

Java API Specification says:

It is strongly recommended that all serializable classes explicitly declare serialVersionUID values, since the default serialVersionUID computation is highly sensitive to class details that may vary depending on compiler implementations, and can thus result in unexpected InvalidClassException’s during deserialization.

therefore it is wise to choose the latter option.

If you’re using a very popular Java development IDE IntelliJ IDEA, you may find it not straightforward, how to generate the serialVersionUID there. Below is the recipe for the IntelliJ IDEA 12 (latest at the time of writing), hope you’ll find it useful:

  • Go to “File” => “Settings… (Ctrl+Alt+S)” => “Inspections” => “Serialization issues”
  • … and enable “Serializable classes without ‘serialVersionUID'”

IntelliJ IDEA - serialVersionUID{:class="blog-center"}

  • Then use the IntelliJ IDEA light bulb or press Alt+Enter to generate the field

IntelliJ IDEA - serialVersionUID{:class="blog-center"}