Hi,
I would like to rename an event class to something different. I could do this by modifying the event store (JDBC), but I would not like to tamper with this.
The old class name ist OrderRegistrationEvent, the new one ContractRegistrationEvent.
Instead I tried to use an upcaster, like this:
@Component
class EventUpcaster : SingleEventUpcaster() {
companion object {
private val OLD_TYPE = SimpleSerializedType(
"com.test.pandia.domain.buildingobject.event.OrderRegisteredEvent",
null
)
private val NEW_TYPE = SimpleSerializedType(
"com.test.pandia.domain.buildingobject.event.ContractRegisteredEvent",
null
)
}
override fun canUpcast(intermediateRepresentation: IntermediateEventRepresentation): Boolean {
return OLD_TYPE == intermediateRepresentation.type
}
override fun doUpcast(intermediateRepresentation: IntermediateEventRepresentation): IntermediateEventRepresentation {
return intermediateRepresentation.upcastPayload(
NEW_TYPE,
Document::class.java
) { document -> document }
}
}
However, there are several questions:
- I only had the
axon-spring-boot-starterdependency declared, but all examples require as second parameter forupcastPayload()aorg.dom4j.Document, which was not available until I addeddom4jas a dependency. How did serializing / deserializing work without this dependency in the first place? - I’ve renamed the class in the code, but it looks like that the original class is required as I get the following error message:
Caused by: com.thoughtworks.xstream.mapper.CannotResolveClassException: de.mnet.pandiacore.domain.buildingobject.event.OrderRegisteredEvent
at com.thoughtworks.xstream.mapper.DefaultMapper.realClass(DefaultMapper.java:81) ~[xstream-1.4.21.jar:1.4.21]
Why do I deserialize into Document when I still need the original class? The only thing that works is to add an alias to XStream for the old class name, but why is this required?