jacksonspring-amqpkotlinx.serialization

How to use kotlinx serialization with Spring AMQP?


It seems that spring AMQP has built-in MessageConverter support for Jackson with the Jackson2JsonMessageConverter class, but is there an equivalent for the kotlinx serialization lib, or would it be necessary to write a custom message converter for it?

Trying to deserialize a JSON AMQP message without providing a MessageConverter Bean will cause an exception


Solution

  • Yes, you have to write your own org.springframework.amqp.support.converter.MessageConverter implementation for Kotlin Serialization.

    It looks like we can borrow ideas from the org.springframework.messaging.converter.KotlinSerializationJsonMessageConverter.

    However you also can use a org.springframework.amqp.support.converter.MessagingMessageConverter with a delegate to the mentioned KotlinSerializationJsonMessageConverter.

    See AbstractRabbitListenerContainerFactory.setMessageConverter(MessageConverter messageConverter).