• Post Reply Bookmark Topic Watch Topic
  • New Topic

Changing object without altering Serial ID  RSS feed

 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We're trying to patch a serialised object used in a production system, we need to add a new field (a java.lang.Long)

We were hoping that making the field transient wouldn't change the serialVersionUID, but it looks like it does. We cannot suddenly add our own serialVersionUID or add custom serialisation, are there any other tricks I should try?

The root of the problem is that this is a persistence object that snuck into the GUI. Someone will get smacked. We have a work around, but this is the more elegent solution.
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[DOM]: We cannot suddenly add our own serialVersionUID

Why not? The "classic" solution would seem to be to add a serialVersionUID which coincidentally matches the old one. Is this not possible?
[ February 07, 2006: Message edited by: Jim Yingst ]
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It could be I guess, but will that cause deserialisation problems or will it be OK with the transient variable?
(I was about to ask how to find the UID but then I remembered its in the error message )
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The transient variable won't hurt anything, because the default serialization won't expect to find a value for it in the object stream. Although Jim makes this sound like a hack, it's really not -- this is a perfectly legitimate use of the serialVersionUID mechanism.
 
Max Habibi
town drunk
( and author)
Sheriff
Posts: 4118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It'll cause problems if you're trying to change the type of an existing field: for example, from String to Long. But if you're just adding new field, then you're fine.
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the valuable contributions.

I ran a test using the transient and UID and haven't had any problems, obviously. Regression testing appears to be fine too.

I'm not sure why I was hestitant to implement the serialVersionUID, I guess it was a combination of 1) we shouldn't be having the problem in the first place and 2) it is not a practice we have encouraged in this application. In the end I had dismissed it without serious consideration.

Thanks for the push.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!