Search code examples
javaavro

AVRO class cast exception


Hi so in my spring listener consumer i keep getting the following error thrown, when i attempt to get the value..

  public void listen(ConsumerRecord<String, Car> consumerRecord) {
    Car value = consumerRecord.value();
    int i= 0;
}

  java.lang.ClassCastException: class org.apache.avro.generic.GenericData$Record cannot be cast to class com.test.avro.Car (org.apache.avro.generic.GenericData$Record and com.test.avro.Car are in unnamed module of loader 'app')

Solution

  • I needed to add the following to the configuration

    props.put(KafkaAvroDeserializerConfig.SPECIFIC_AVRO_READER_CONFIG, "true");