SpringSpring Kafka Advanced
How do you configure Spring Kafka for JSON serialization with type information?
Reference answer
Use JsonSerializer/JsonDeserializer. Add type header: spring.kafka.producer.properties.spring.json.add.type.headers=true. On consumer, trust packages: spring.kafka.consumer.properties.spring.json.trusted.packages=com.example.*. Or use spring.kafka.consumer.properties.spring.json.value.default.type=com.example.MyDto to always deserialize to a specific type regardless of headers. For Schema Registry-backed Avro: use io.confluent.kafka.serializers.KafkaAvroSerializer/Deserializer with schema.registry.url property.
Expected key concepts: JsonSerializer, JsonDeserializer, spring.json.add.type.headers, spring.json.trusted.packages, spring.json.value.default.type, Avro, schema.registry.url, KafkaAvroSerializer, type headers