Search code examples
spring-bootaxon

Can i use jackson and xstream serializers for same event across mutiple services


I have 2 spring boot micro-services core and web:

The core service reacts to some event (EmployeeCreatedEvent) which is triggered by web. The core service is using jackson serializer to serialize commands, queries, events and messages whereas the web service is using xstream serializer. i am getting below error in core while handling EmployeeCreatedEvent triggered by web:

Caused by: com.fasterxml.jackson.core.JsonParseException: Unexpected character (’<’ (code 60)): 
expected a valid value (JSON String, Number, Array, Object or token ‘null’, ‘true’ or ‘false’)

i am using below properties (jackson for core and default for web):

axon.serializer.general = jackson/default
axon.serializer.events = jackson/default
axon.serializer.messages = jackson/default

can someone suggest whether it is ok to use different serializer for same event in different services.


Solution

  • I agree with @Augusto here and you should make a decision about which serialization format you are going to use across all your services.

    I am assuming you started with the default serializer (which is XStream and XML) and later on decided to move to Jackson (which is JSON). In that case, there are 2 advices I can share with you:

    • You can write a Custom Serializer which have both implementations and try with both of them and see which one works, for example trying with XML and fallbacking to JSON.

    • Or you can have a Component which will listen to all Events from your EventStore, deserialize them using XStream and write them back to another EventStore using Jackson. In this case, for this migration period, you will have this component using 2 Event Streams (one for each EventStore) but after the migration is done your whole EventStore will be in JSON. This requires some work but is the best approach in my opinion and will save you a lot of time and pain in the future. You can look more about configuring 2 sources here.