Some class has no definition of serialVersionUID : explain, please

1,621 views
Skip to first unread message

Serega....@gmail.com

unread,
Dec 7, 2007, 8:15:51 AM12/7/07
to Google Web Toolkit
warning: [serial] serializable class
ru.gamedev.client.gameitem.GameItem has no definition of
serialVersionUID


public class GameItem implements Serializable{

public GameItem(){}

public GameItem(int a, int b){}
}
}



and the second class:



public class GameItemHat extends GameItem{

public GameItemHat(){}

public GameItemHat(int a, int b, String s){
super(a,b);
}
}


Is that true:

1.I've done everything to have an ability to create GameItem and
GameItemHat on the server-side and transfer to client-side
2.GameItemHat also implements Serializable ... or I have to do write
it again?

Charlie Collins

unread,
Dec 7, 2007, 8:59:03 AM12/7/07
to Google Web Toolkit
That's just a warning, you need not really worry about it for GWT
purposes. In standard Java serialization though,
java.io.Serializable, it is a best practice to implement this field
and increment if you change the class - so that existing serialized
instances aren't confused if the class is updated.

http://mindprod.com/jgloss/serialization.html#SERIALVERSIONUID



On Dec 7, 8:15 am, "Serega.Shey...@gmail.com"

mP

unread,
Dec 10, 2007, 8:07:15 PM12/10/07
to Google Web Toolkit
Think of it as a version number for the class definition. If you add
your own serialuid, each time you change/add/remove a field you should
update the serialuid so that it contains a different number.

Basically imagine one jvm holding a version of class X with serialuid
of 1 and an instance gets send to a second jvm. If the 2nd jvm class X
has a serialuid of 1 then its safe to assume that the structure of X
is the same or compatible. However if there is a mismatch then they
are incompatible and an exception will be thrown when the 2nd jvm
attempst to deserialize the X instance it recieved from jvm1.

On Dec 8, 12:15 am, "Serega.Shey...@gmail.com"
Reply all
Reply to author
Forward
0 new messages