Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Configure Eclipse's serialVersionUid Quick Fix

 
Greg Charles
Sheriff
Posts: 2985
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Several code generators (and code monkeys) create serializable classes with no explicit serialVersionUid set. By default, Eclipse puts warnings on these classes. However, it does have a "Quick Fix" that automatically add either a generated or default serialVersionUid declaration, preceded by an empty JavaDoc comment. What if I want to change this output ... say fill in the JavaDoc, or delete it entirely? Or maybe change the default value for the the id? I've looked through the code templates, but nothing is jumping out at me.
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18096
49
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think this is also likely to cause the Java compiler to spit out a warning. However, if you look at the suggested fixes that Eclipse offers, you'll see that there's also an option to ignore the missing Serial version ID. It causes an annotation to be placed just ahead of the class definitions.

Actually, it's not a bad idea to use the serial version ID. It doesn't require much space and it may someday keep you out of trouble when working with serialized objects that are being passed around between different releases of code.

Then again, there are times when you get this because you're working with a class that's defined as serializable even though you never intend to actually serialize it. Which is why you have the option to suppress the warning.
 
Greg Charles
Sheriff
Posts: 2985
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh, probably I wasn't clear. I do want to have the serial version id; I just want to have control of what Eclipse puts there. In particular, I don't like the empty comment it generates, since that means I have to either fill the comment in or delete it entirely.
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18096
49
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh that. Ugly, ain't it? It should be coming from the same place that general member comment JavaDoc prototypes do, except I think it's missing something.
 
Peter Johnson
author
Bartender
Posts: 5852
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, the number it assigns is some kind of hash that it gets from compiling the class. Usually, when I make any changes I remove the value and rerun the quickfix to get an updated number.

If you have your own standards for the serial version id, create a template for it and use that.
 
Doug Crews
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Window - Preferences - Java - Code Style - Code Templates - Comments - Fields

Default value is:

/**
*
*/

Change to empty string, and your problem is solved. Worked for me at least.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic