spring-batch icon indicating copy to clipboard operation
spring-batch copied to clipboard

Fix KafkaItemReader ExecutionContext deserialization error when using Jackson2ExecutionContextStringSerializer

Open noojung opened this issue 5 months ago • 0 comments

When use Jackson2ExecutionContextStringSerializer, KafkaItemReader always encountered an ClassCastException.

Because KafkaItemReader stores a Map<TopicPartition, Long> in the ExecutionContext, Jackson2ExecutionContextStringSerializer forces all map keys to String.

So I change it to store only the partition number (as String) instead of TopicPartition directly.

This change:

  • Modifies update() to save only the partition number (as a String) into the ExecutionContext
  • Updates open() to read those String offsets and reconstruct each TopicPartition

As a result, KafkaItemReader can now successfully deserialize ExecutionContext without throwing an exception.

Resolves: #3797

noojung avatar Jun 05 '25 12:06 noojung