Changes on event classes that were serialized and persisted

Hi everyone,

While working on a sample project, I got this exception after changing the package structure of my event classes. (Qualified name of event class is changed.):

…xstream.mapper.CannotResolveClassException : old_package_name.MyEventClass

So, serialized events that were saved to DB are tried to be deserialized. But their definitions were changed.

How can we migrate our data in these situations? I don’t have much experience on event sourcing.

Thanks in advance.
Bahadır Konu

Hi Bahadir,

generally, you use Upcasters to convert “old” serialized events to the new format. There is a small section about that in the reference manual:

Alternatively, if you use XStream, you can add an alias from the old package name to the new one. To make sure the new events are stored under their own package name, you have to add the alias twice, like so:\

serializer.addPackageAlias(“”, “”); // makes sure old package is read in as new.package
serializer.addPackageAlias(“”, “”); // makes sure that new.package is also written as new.package

This removes the need for upcasters and performs a lot better too.



2011/11/29 Bahadır Konu <>