• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Configure Eclipse's serialVersionUid Quick Fix

 
Sheriff
Posts: 3063
12
Mac IntelliJ IDE Python VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Saloon Keeper
Posts: 27762
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 3063
12
Mac IntelliJ IDE Python VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 27762
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author
Posts: 5856
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
I’m tired of walking, and will rest for a minute and grow some wheels. This is the promise of this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic