Kafka Exception SerializationException
org.apache.kafka.common.errors.SerializationException
Non-retriable
Serialization
Any exception during serialization in the producer
Common Causes
- The configured key.serializer / value.serializer cannot serialize the object type you passed to producer.send() (e.g. sending a POJO with StringSerializer)
- Schema Registry serializer (Avro/Protobuf/JSON Schema) failed to register or fetch a schema, or the subject's compatibility rules rejected the payload
- On the consumer side, the bytes on the topic do not match the configured deserializer (wrong format, or a producer wrote with a different serializer)
Solutions
- Match the serializer to the data type (StringSerializer for String, KafkaAvroSerializer for Avro records, ByteArraySerializer for raw bytes)
- If using Schema Registry, verify schema.registry.url, credentials, and subject compatibility; check the schema is registered for the topic-value subject
- Wrap consumer deserialization with ErrorHandlingDeserializer (Spring Kafka) or a try/catch to route poison-pill records to a dead-letter topic instead of crashing the consumer
Example Stack Trace
org.apache.kafka.common.errors.SerializationException: Can't convert value of class com.example.Order to class org.apache.kafka.common.serialization.StringSerializer specified in value.serializer
at org.apache.kafka.common.serialization.StringSerializer.serialize(StringSerializer.java:50)
at org.apache.kafka.clients.producer.KafkaProducer.doSend(KafkaProducer.java:1010)Related
Related Serialization exceptions: RecordDeserializationException
Hitting
SerializationException in production? Conduktor Console gives you real-time visibility into clients, consumer groups, and broker health. Browse every Kafka exception or protocol error code.