Hi,
I noticed a strange behaviour.
When using a StringJsonMessageConverter the Payload Class Type cannot determined because the passed Method constructor param is null in MessagingMessageListenerAdapter. Therefore the field inferredType stays null and the fallback java.lang.Object is used which yields to erronous HashMap conversion of my JSON object.
This is only related to usage of @KafkaListener class annotation with @KafkaHandler method annotation. Another test where I use a @KafkaListener annotation directly the Payload is converted to TestEvent correctly:
@KafkaListener(topics = "product", groupId = KafkaEventConsumerRegistry.KAFKA_GROUP_ID)
public void handleEvent(@Payload TestEvent event) {
LOGGER.error(LogMarker.KAFKA, "Event: " + event.getTest()); // Works
}
@KafkaListener(topics = KafkaEventPublisher.ORDER_TOPIC, groupId = KafkaEventConsumerRegistry.KAFKA_GROUP_ID)
public class KafkaEventListener {
@KafkaHandler
public void listenTo(@Payload KafkaEvent event) throws Exception {
LOGGER.error(LogMarker.KAFKA, "Event: " + event); // ClassCastException, cannot convert HashMap to KafkaEvent
}
}
I guess this should work also for the combined annotation variant.
For now I will change my code to use only @KafkaListener annotation.