Re: java serialization alternative
Attila Szegedi <[email protected]> Sun, 30 Mar 2008 10:03:12 +0200
| Newsgroups | gmane.comp.windows.devel.java.advanced |
|---|---|
| Message-ID | <[email protected]> |
On 2008.03.29., at 23:45, Bob Lee wrote: > Making compatible changes isn't hard. Identifying incompatible > changes, for example if a programmer makes a change to a class but > forgets to consider serialization, is very tricky. Oh yes, I completely agree with that. > You simply can't > verify compatibility statically with serialization. Yep, one could actually append "... by definition" here, right? :-) > The only way to > verify that two classes are compatible is to run them and test them. > You can either keep serialized data around in a file or something, or > you can use a trick like this: > http://crazybob.org/2006/01/unit-testing-serialization-evolution_13.html > . > Either approach is a pain in the butt. Right - the real pain (which your blog entry doesn't show) is when both classes are actually two versions of the same class, so you must ensure you have both .class files available somewhere, have them loaded through different class loaders, and then persuade the ObjectInputStream to deserialize to the right class (as it's notoriously ignorant of thread context class loader...). PITA indeed. Although, alternatively, you could try reading ObjectStreamClass and its ObjectStreamField objects from the stream and comparing them against the in-memory class... oh well, actually you can't as if the object has a custom writeObject/readObject, or is Externalizable, this approach'd fail. (Just thinking out loud.) > > > If you use a tool like Thrift, you can check two definitions for > compatibility statically, so for example, you could add a submit check > to your source control system or test suite to detect incompatible > changes. Nice - thanks for the pointer. I wonder how easy is it to extract this functionality from Thrift, as otherwise it seems to be geared toward RPC, and I'm more on the async messaging side of architecture... Attila. =================================== This list is hosted by DevelopMentorĀ® http://www.develop.com View archives and manage your subscription(s) at http://discuss.develop.com