java.lang.VerifyError: Bad return type when using org.springframework.kafka.support.serializer.JsonDeserializer()

Good day,

Base on Synchronous Kafka: Using Spring Request-Reply - DZone Big Data , I would like to try the Synchronous Kafka.

However, when I trying to creating the bean of ConsumerFactory. I am hitting the java.lang.VerifyError: Bad return type error.

My code is as follow:

import org.springframework.kafka.support.serializer.JsonDeserializer;

||// Default Consumer Factory|
|---|---|
||@Bean|
||public ConsumerFactory<String, JSONObject> consumerFactory() {|
||  return new DefaultKafkaConsumerFactory<>(producerConfigs(),new StringDeserializer(),new JsonDeserializer<>(JSONObject.class));|
||}|

In the gradle dependency, I can see its using com.fasterxml.jackson.core:jackson-databind:2.10.5.1:
image

And the error in my eclipse console is as follow:


WFLYCTL0186:   Services which failed to start:      service jboss.undertow.deployment.default-server.default-host./eai: java.lang.RuntimeException: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'ReplyingKafkaTemplate' defined in com.beans.eai.config.WebConfig: Unsatisfied dependency expressed through method 'replyKafkaTemplate' parameter 1; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'replyContainer' defined in com.beans.eai.config.WebConfig: Unsatisfied dependency expressed through method 'replyContainer' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'consumerFactory' defined in com.beans.eai.config.WebConfig: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.kafka.core.ConsumerFactory]: Factory method 'consumerFactory' threw exception; nested exception is java.lang.VerifyError: Bad return type
Exception Details:
  Location:
    com/fasterxml/jackson/databind/cfg/MapperBuilder.streamFactory()Lcom/fasterxml/jackson/core/TokenStreamFactory; @7: areturn
  Reason:
    Type 'com/fasterxml/jackson/core/JsonFactory' (current frame, stack[0]) is not assignable to 'com/fasterxml/jackson/core/TokenStreamFactory' (from method signature)
  Current Frame:
    bci: @7
    flags: { }
    locals: { 'com/fasterxml/jackson/databind/cfg/MapperBuilder' }
    stack: { 'com/fasterxml/jackson/core/JsonFactory' }
  Bytecode:
    0x0000000: 2ab4 0002 b600 08b0

Is it I need to use another version of the library to handle this?

What version of Spring Boot are you using? The first thing I would do is look at the version of Jackson that Spring Boot was built with; e.g. for 2.7.0 here is a list of verions

https://docs.spring.io/spring-boot/docs/2.7.0-M3/reference/htmlsingle/#appendix.dependency-versions

Also, you should try to stick as close to the version of Kafka that is recommended with the spring library you are using. There should be notes on that as well.

and then use the Confluent version that aligns with that version of Java; since Confluent’s use of Jackson usually aligns with the version of Kafka it is based on.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.