KafkaException: class is not an instance of org.apache.kafka.common.serialization.Deserializer

后端 未结 2 868
情书的邮戳
情书的邮戳 2021-01-27 12:26

I want to implement Kafka producer which sends and receives Java Serialized Objects. I tried this:

Producer:

@Configuration
publi         


        
2条回答
  •  -上瘾入骨i
    2021-01-27 12:41

    You are using different type to cast the object than what it was serialize with. Not sure why you need to do that. You can update your deserialize to something like below.

    public class SaleRequestFactoryDeserializer implements Serializable, Deserializer {
    
         @Override
         public SaleRequestFactory deserialize(String topic, byte[] data) {
          ...
            saleRequestFactory = (SaleRequestFactory) in.readObject();
    
        }
    }
    
    java.lang.ClassCastException: null
    

    This also means your serialization didn't work as expected. Make sure you have valid payload before you try to cast.

提交回复
热议问题