john pfeiffer
  • Home
  • Categories
  • Tags
  • Archives

serializable warning

"The serializable class Login does not declare a static final serialVersionUID field of type long"


If your class implements "Serializable" (HttpServlet does) you need an id because if the Servlet-Context
 is relaunched and your sessions should be made persistant / restored.
(If you don't need this feature, you don't need a serialVersionId.)


"Object serialization is the process of saving an object's state to a sequence of bytes,
as well as the process of rebuilding those bytes into a live object at some future time."

import java.io.FileOutputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;


public class myExampleClass implements Serializable {

public static void main(String [] args)
{
  myExampleObject time = new myExampleObject();
  FileOutputStream fos = new FileOutputStream(filename);
  ObjectOutputStream out = new ObjectOutputStream(fos);

  out.writeObject( time );

}

http://java.sun.com/developer/technicalArticles/Programming/serialization/
http://www.mactech.com/articles/mactech/Vol.14/14.04/JavaSerialization/index.html
http://mindprod.com/jgloss/serialization.html

SerialVersionUID generation may differ by compiler, SUID is a measure of backwards compatibility,
to ensure different clients with different JVM's won't have compiler generated incompatibilities
you should generate your own SUID and update it when you update the code.


- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
SOLUTION
Eclipse IDE: click on the light bulb and choose add default serial version id.

// default serial version id inserted by Eclipse
private static final long serialVersionUID = 1L;

  • « Linux bash date continued
  • html basic headers »

Published

Jun 5, 2011

Category

java

~183 words

Tags

  • java 252
  • serializable 1
  • warning 1