Getting jackson-databind serialization error after updating spring boot

Viewed 359

I have a serialization problem after updating spring boot from 2.1.8.RELEASE to 2.2.13.RELEASE.
Dependency explicitly changed are as follows. (The rest would have been implicitly changed by updating Spring Boot)

As-is

  • springBootVersion = '2.1.8.RELEASE'
  • spring-integration-kafka = '3.0.4.RELEASE'
  • jackson-module-kotlin = '2.9.9'
  • jackson-core = '2.10.0'
  • jackson-databind = 2.10.0'

To-be

  • springBootVersion = '2.2.13.RELEASE'
  • spring-integration-kafka = '3.2.1.RELEASE'
  • jackson-module-kotlin = '2.10.5'
  • jackson-core = '2.10.5'
  • jackson-databind = 2.10.5.1'

After updating it, errors that was not occurred before is reported like this.

@Bean
fun commonListenerErrorHandler(): ConsumerAwareListenerErrorHandler {
    return ConsumerAwareListenerErrorHandler { message, exception, _ ->
        val mapper = ObjectMapper().registerModule(KotlinModule())
        val headerMap = mutableMapOf<String, String>()

        val data = hashMapOf<String, Any>(
            // message.payload is org.apache.kafka.clients.consumer.ConsumerRecord
            "message" to mapper.writeValueAsString(message.payload),
            "header" to mapper.writeValueAsString(headerMap)
        )
        doSomething(mapper.writeValueAsString(data)) // Error occurred!
    }
}

nested exception is com.fasterxml.jackson.databind.exc.InvalidDefinitionException: No serializer found for class org.apache.kafka.clients.consumer.ConsumerRecord and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS)

I'm really confused why this error is occurring after updating spring-boot and it's related dependencies. I am attaching the actual code. I found some SO questions org.apache.kafka.clients.consumer.ConsumerRecord is not serializable when it's used in spark streaming, but if it's not serializable why it was run normally before updating spring boot? Is it related any changes in jackson databind update?

0 Answers
Related