Let me try to help you… first thing, looking at your code and comparing to the link you provided, the error is on the ‘type’ you are sending to the upcastPayload method.
In your example, you are sending the IntermediateEventRepresentation.class while it should be org.dom4j.Document.class (since you are working with XML, JsonNode.class if you were working with Json).
By fixing that, creating your Stream of IntermediateEventRepresentation should work.
Nonetheless, I created an issue on our code-sample to expand what we already have there to add another examples and samples.
Here, I would like to point a couple of small notes, if you allow me:
Looking at your events being called Create* and Update*, seems like you are following a CRUD approach. This is not something we commonly see when working with DDD as your events should have some meaning.
As already stated before, you are using XML but I would recommend you to have a look at using Json (and Jackson) for storing your events. It’s more ‘human readable’ and the size of the event is a lot smaller.
On your example, you are trying to upcast 2 times (you call upcastPayload two times). The second time is almost correct, where you are using the correct type there but the first one not. You should revisit that piece of code.
Actually I refactored my code as it could be seen above.
Now the problem is when I enter getUpcastTwo method I have document passed as MenuCreatedEvent, but it should be MenuUpdatedEvent. So I’m getting java.lang.IllegalArgumentException: argument type mismatch Error.
So could you please take a look again at my piece of code and point me on a mistake.
Because in my project is getting more and more EventUpcasting and I want to use EventMultiUpcaster instead of SingleEventUpcaster
P.S.
Do I have to check canUpcast method for all the events? or just for the first event ?