title: common.KafkaException: com.fasterxml.jackson.databind.ser.std.StringSerializer is not an instance of org.apache.kafka.common.serialization.Serializer
body: <p>I am developing <code>Spring Boot + Apache Kafka</code> example. While sending <code>TOPIC</code> to Kafka getting error.</p>
  
  <p>Error:</p>
  
  <pre><code>java.lang.IllegalStateException: Failed to execute CommandLineRunner
      at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:816) [spring-boot-2.1.1.RELEASE.jar:2.1.1.RELEASE]
      at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:797) [spring-boot-2.1.1.RELEASE.jar:2.1.1.RELEASE]
      at org.springframework.boot.SpringApplication.run(SpringApplication.java:324) [spring-boot-2.1.1.RELEASE.jar:2.1.1.RELEASE]
      at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260) [spring-boot-2.1.1.RELEASE.jar:2.1.1.RELEASE]
      at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248) [spring-boot-2.1.1.RELEASE.jar:2.1.1.RELEASE]
      at com.demo.kafka.SpringBootKafkaJsonApplication.main(SpringBootKafkaJsonApplication.java:17) [classes/:na]
  Caused by: org.apache.kafka.common.KafkaException: Failed to construct kafka producer
      at org.apache.kafka.clients.producer.KafkaProducer.&lt;init&gt;(KafkaProducer.java:457) ~[kafka-clients-2.0.1.jar:na]
      at org.apache.kafka.clients.producer.KafkaProducer.&lt;init&gt;(KafkaProducer.java:289) ~[kafka-clients-2.0.1.jar:na]
      at org.springframework.kafka.core.DefaultKafkaProducerFactory.createKafkaProducer(DefaultKafkaProducerFactory.java:318) ~[spring-kafka-2.2.2.RELEASE.jar:2.2.2.RELEASE]
      at org.springframework.kafka.core.DefaultKafkaProducerFactory.createProducer(DefaultKafkaProducerFactory.java:305) ~[spring-kafka-2.2.2.RELEASE.jar:2.2.2.RELEASE]
      at org.springframework.kafka.core.KafkaTemplate.getTheProducer(KafkaTemplate.java:437) ~[spring-kafka-2.2.2.RELEASE.jar:2.2.2.RELEASE]
      at org.springframework.kafka.core.KafkaTemplate.doSend(KafkaTemplate.java:367) ~[spring-kafka-2.2.2.RELEASE.jar:2.2.2.RELEASE]
      at org.springframework.kafka.core.KafkaTemplate.send(KafkaTemplate.java:184) ~[spring-kafka-2.2.2.RELEASE.jar:2.2.2.RELEASE]
      at com.demo.kafka.config.producer.Sender.send(Sender.java:28) ~[classes/:na]
      at com.demo.kafka.SpringBootKafkaJsonApplication.run(SpringBootKafkaJsonApplication.java:22) [classes/:na]
      at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:813) [spring-boot-2.1.1.RELEASE.jar:2.1.1.RELEASE]
      ... 5 common frames omitted
  Caused by: org.apache.kafka.common.KafkaException: com.fasterxml.jackson.databind.ser.std.StringSerializer is not an instance of org.apache.kafka.common.serialization.Serializer
      at org.apache.kafka.common.config.AbstractConfig.getConfiguredInstance(AbstractConfig.java:304) ~[kafka-clients-2.0.1.jar:na]
      at org.apache.kafka.clients.producer.KafkaProducer.&lt;init&gt;(KafkaProducer.java:362) ~[kafka-clients-2.0.1.jar:na]
      ... 14 common frames omitted
  </code></pre>
  
  <p>Sender.java</p>
  
  <pre><code>@Data
  @NoArgsConstructor
  public class Sender {
  
      private static final Logger LOGGER = LoggerFactory.getLogger(Sender.class);
  
      @Value("${kafka.topic-json}")
      private String jsonTopic;
  
      @Autowired
      private KafkaTemplate&lt;String, Car&gt; kafkaTemplate;
  
      public void send(Car car) {
          LOGGER.info("sending car='{}'", car.toString());
          kafkaTemplate.send(jsonTopic, car);
      }
  }
  </code></pre>
  
  <p>SenderConfig.java</p>
  
  <pre><code>@Configuration
  public class SenderConfig {
      @Value("${kafka.bootstrap-servers}")
      private String bootstrapServers;
  
      @Bean
      public Map&lt;String, Object&gt; producerConfigs() {
          Map&lt;String, Object&gt; props = new HashMap&lt;&gt;();
          props.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapServers);
          props.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class);
          props.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, JsonSerializer.class);
  
          return props;
      }
  
      @Bean
      public ProducerFactory&lt;String, Car&gt; producerFactory() {
          return new DefaultKafkaProducerFactory&lt;&gt;(producerConfigs());
      }
  
      @Bean
      public KafkaTemplate&lt;String, Car&gt; kafkaTemplate() {
          return new KafkaTemplate&lt;&gt;(producerFactory());
      }
  
      @Bean
      public Sender sender() {
          return new Sender();
      }
  }
  </code></pre>
  
  <p>Receiver.java</p>
  
  <pre><code>public class Receiver {
  
      private static final Logger LOGGER = LoggerFactory.getLogger(Receiver.class);
  
      private CountDownLatch latch = new CountDownLatch(1);
  
      public CountDownLatch getLatch() {
          return latch;
      }
  
      @Value("${kafka.topic-json}")
      private String jsonTopic;
  
      @KafkaListener(topics = "jsont")
      public void receive(Car car) {
          LOGGER.info("received car='{}'", car.toString());
          latch.countDown();
      }
  }
  </code></pre>
  
  <p>ReceiverConfig.java</p>
  
  <pre><code>@Configuration
  @EnableKafka
  public class ReceiverConfig {
  
      @Value("${kafka.bootstrap-servers}")
      private String bootstrapServers;
  
      @Bean
      public Map&lt;String, Object&gt; consumerConfigs() {
          Map&lt;String, Object&gt; props = new HashMap&lt;&gt;();
          props.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapServers);
          props.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class);
          props.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, JsonDeserializer.class);
          props.put(ConsumerConfig.GROUP_ID_CONFIG, "json");
  
          return props;
      }
  
      @Bean
      public ConsumerFactory&lt;String, Car&gt; consumerFactory() {
          return new DefaultKafkaConsumerFactory&lt;&gt;(consumerConfigs(), new StringDeserializer(),
                  new JsonDeserializer&lt;&gt;(Car.class));
      }
  
      @Bean
      public ConcurrentKafkaListenerContainerFactory&lt;String, Car&gt; kafkaListenerContainerFactory() {
          ConcurrentKafkaListenerContainerFactory&lt;String, Car&gt; factory =new ConcurrentKafkaListenerContainerFactory&lt;&gt;();
          factory.setConsumerFactory(consumerFactory());
          return factory;
      }
  
      @Bean
      public Receiver receiver() {
          return new Receiver();
      }
  }
  </code></pre>
  
  <p>MainJava</p>
  
  <pre><code>@SpringBootApplication
  public class SpringBootKafkaJsonApplication implements CommandLineRunner {
      @Autowired
      private Sender sender;
  
      public static void main(String[] args) {
          SpringApplication.run(SpringBootKafkaJsonApplication.class, args);
      }
  
      @Override
      public void run(String... args) throws Exception {
          sender.send(Car.builder().id("1").make("ALTO").manufacturer("Maruti Suzuki").build());
      }
  }
  </code></pre>
  
  <p>application.yml</p>
  
  <pre><code>kafka:
    topic-json: jsont
    bootstrap-servers: localhost:9092
  </code></pre>