I’ve set up a project with the Axon 2.0 snapshot. I want my event store as well as my event bus to use a JSON serializer. Unfortunately, just passing a XStream implementation that generates JSON does not seem sufficient. Something like:
return new XStreamSerializer(new XStream(new JsonHierarchicalStreamDriver()));
Is there something I am missing or should I implement my own serializer, also extending the parent of XStreamSerializer ? Furthermore, is there any reason behind the format used ? I’m in a mixed environment with many technologies and, as such, cannot rely on the XStreamSerializer.
if I remember correctly, the JsonHierarchicalStreamDriver can only serialize to JSON, not deserialize from it. In the Axon Mongo package I have made a BSON serializer. Maybe you can use that one instead? Otherwise, you’ll have to implement your own serializer using one of the JSON libraries.
Thank you for your responses. I ended up using the BSON converter and am very pleased with the result. One thing that tickles me a bit though is I wish the whole message could be formatted with JSON, and not only the payload. I realize this is done by the EventMessageWriter, and there’s no way to pass a different implementation to the AMQP terminal. Am I missing something ? Also, maybe I’m misguided in wanting to have the whole message as a JSON object. Is there a particular reason this format is used ? My main concern is integration with other technologies.
you’re on the bleeding edge of Axon development here. I think your remark is completely correct. The serialization of the message as a whole (currently done by the EventMessageWriter) should be configurable.
The reason why I don’t serialize the entire message as a whole is because one would only want to deserialize the payload if there really is a listener for it. There is a big performance benefit if the payload (or meta data) is lazily deserialized.
I’ll incorporate some configuration options in the near future.