Hi,
I’m using EventSourcing, backed by a JPA repository.
I would like to refactor some of my events, but as my application is already under testing, I’m wondering how I can deal with it gracefully.
Let’s say that I have a event E, with some fields attribute1,attribute2,attribute3.
Now, for some reason, I would like to group attribute1, attribute2, attribute3 inside a value object.
public class E {
private ValueObject valueObject;
}
public class ValueObject {
private String attribute1;
private String attribute2;
private String attribute3;
}
I guess that if I do that without any other modification, I’ll end up with an inconsistent state when my events will be applied to my AggregateRoot (as valueObject will be null, or worse, I’ll get a exception as attribute1, attribute2, attribute3 are not found at this level by the deserializer).
So my question is very simple, to handle that case, what’s the most straightforward (and consistent) way ?
Implementing a upcaster, or using a custom deserializer on XStream side ? (In the case of Xstream, I’m not sure how to deal with the 3 attributes mapping).
The documentation recommends to avoid upcasting when possible, and in the current case, I tend to agree, as I don’t really change the Event itself.
Thank you,