Details
-
Type:
New Feature
-
Status:
Open
-
Priority:
Minor
-
Resolution: Unresolved
-
Affects Version/s: 1.0.4
-
Fix Version/s: None
-
Component/s: XML code generator
-
Labels:None
-
Number of attachments :
Description
Recently there had been 2 requests to generate serial version UID for generated classes. Following conversation took place on user mailing list at one of these threads.
its my understanding that the de-serialization process is highly dynamic
and tries to deal with many (most?) incompatiblities between a
serialized version and the actual class. I.e., it skips values that are
not present in the class, etc. So, in most cases the de-serialization
will produce a valid result. So, I think, in almost all situations
retaining the same serial uid will work just fine. In fact, there is
almost no reason to generate uids ... any value, say 1, will do.
There may be a situation where you don't want to (or really can't)
de-serialize an 'old' version of some class - but this is the exception
and not the rule.
Moreover, this issue only applies to situations where serialized forms
of objects are actually persisted or transmitted between potentially
different versions. But object serialization is not a particularly good
way to persist data (Castor JDO?).
So, I would say that having the generator use some fixed value by
default and allowing a binding file to overrule the default would imho
work just fine.
----Original Message----
From: Ralf Joachim ralf.joachim@syscon-world.de
Sent: Friday, October 13, 2006 4:19 PM
To: Castor - User
Subject: [castor-user] Re: Castor serialVersionUID
Hi Dion,
I generated serial version UID for all classes that implement
java.io.Serializable interface but are not generated by source generator
with eclipse. If your class implements the java.io.Serializable
interface and it does not have a serial version UID then Eclipse will
give a warning about this next to the class name. If you click on the
warning you can choose the option "Add generated serial version ID."
There is also the possibility to generate serial version UID's with
serialver tool from jdk. An example commandline would be:
serialver -classpath 'build;C:/foo/classes.jar' com.bar.FooMessage
But I guess you are would like to get them automatically generated when
you generate java sources with castor's source generator. If this was
your intention i have only bad news for you as this is not supported
yet, even if I think that would be a quite usefull feature.
If like this feature to get added I suggest you to open a new
enhancement request at: http://jira.codehaus.org/browse/CASTOR
Having said that this task looks very simple on the first view but get
very tricky if you take a deeper look. The problem is how to handle
serial version UID's if you generate source for the second time e.g.
with a new version of castor or after changing the schema. What would
you expect to happen with the serial version UID's in that case?
1. You generate new serial version UID's independend of the ones in the
old source files. This will cause all serial version UID's to get
changed. But then you wouldn't be able to deserialize objects with the
new classe that have been serailized with the old ones e.g. if they got
persisted somewhere.
2. Take serial version UID's from old source files and use them also for
the new ones. A quite similar option of that would be to use serial
version UID'S that are defined in binding file. With this option you
would be able to deserialize objects with new new classes that have been
serialized with the old ones as long as they have similar properties.
The problem that you will face here happens if the generated classes
have new properties or some other significant changes that may cause
deserialization to fail.
3. To also resolve problems with significant changes to generated
classes you first need to detect these changes and generate readResolve
methods that are able to deserialize old serialized objects into new
ones. I would expect this task to be quite complicated.
Please let me know your thoughts and what you would expect castor to
handle the situation described above.
Regards
Ralf
Castor JDO, committer
PS: I will also forward this mail to castor user list so others can jump
in and tell us their opinons.
Dion Sayles schrieb:
>> Hi Ralf,
>>
>> I am currently working with castor 1.0.3 and trying to get the
>> serialVersionUID generated in the Java code that is produced by it.
>> Since you provided the patch to do that, I was wondering if you could
>> possibly take the time to direct me towards documentation
>> for how to actually have it generated? Are there properties that need
>> to be configured? Or new elements in the defining XML
>> file?
>>
>> Thank you for your time...
>>
>> -dion
Has there been any work on this?
It has been open for quite long now.
Regards,
Giriraj.