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

后端 未结 2 865
情书的邮戳
情书的邮戳 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条回答
  • 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<SaleRequestFactory> {
    
         @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.

    0 讨论(0)
  • 2021-01-27 12:59

    KEY_DESERIALIZER_CLASS_CONFIG is a class which deserializes the network value into proper Java classes. The class you provided doesn't do that.

    In most cases, StringDeserializer is used. Specify a proper deserializer to the factory properties.

    0 讨论(0)
提交回复
热议问题