This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes IDEs, Version Control and other tools and the fly likes Configure Eclipse's serialVersionUid Quick Fix Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Engineering » IDEs, Version Control and other tools
Reply Bookmark "Configure Eclipse Watch "Configure Eclipse New topic
Author

Configure Eclipse's serialVersionUid Quick Fix

Greg Charles
Bartender

Joined: Oct 01, 2001
Posts: 2542
    
  10

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

Joined: Jun 25, 2001
Posts: 14491
    
    7

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.


Customer surveys are for companies who didn't pay proper attention to begin with.
Greg Charles
Bartender

Joined: Oct 01, 2001
Posts: 2542
    
  10

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

Joined: Jun 25, 2001
Posts: 14491
    
    7

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

Joined: May 14, 2008
Posts: 5536

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.


JBoss In Action
Doug Crews
Greenhorn

Joined: Nov 19, 2004
Posts: 3
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Configure Eclipse's serialVersionUid Quick Fix
 
Similar Threads
Wow, never quite realized this before...
RMI and serialID
stupid javadoc question
Deserialisation when unique ID has changed
ArrayList problem ...