Inject ObjectMapper into Spring Kafka serialiser/deserialiser
You can configure JsonSerializer
and JsonDeserializer
as @Bean
s.
Inject a desired ObjectMapper
to them. And use those beans in the DefaultKafkaProducerFactory
and DefaultKafkaConsumerFactory
bean definitions:
@Bean
public ProducerFactory<Integer, String> producerFactory() {
DefaultKafkaProducerFactory<Integer, String> producerFactory =
new DefaultKafkaProducerFactory<>(producerConfigs());
producerFactory.setValueSerializer(jsonSerializer());
return producerFactory;
}