title: Kafka - Deserializing the object in Consumer
body: <p>We are considering to use Kafka in our for messaging and our applications are developed using Spring. So, we have planned to use spring-kafka.</p>
  
  <p>The producer puts the message as HashMap object into the queue. We have JSON serializer and we assumed that the map will be serialized and put into the queue. And here is the producer config. </p>
  
  <pre><code>spring:
    kafka:
      bootstrap-servers: localhost:9092
      producer:
          key-serializer: org.springframework.kafka.support.serializer.JsonSerializer
          value-serializer: org.springframework.kafka.support.serializer.JsonSerializer
  </code></pre>
  
  <p>On the other hand, we have a listener which listens to the same topic where the producer has published the message. Here is the consumer config:</p>
  
  <pre><code>spring:
     kafka:
         consumer:
              group-id: xyz
              key-deserializer: org.springframework.kafka.support.serializer.JsonDeserializer
              value-deserializer: org.springframework.kafka.support.serializer.JsonDeserializer
  </code></pre>
  
  <p>Our listener method:</p>
  
  <pre><code>  public void listener(SomeClass abx)
  </code></pre>
  
  <p>We were expecting the json will be de-serialized and an object of type "SomeClass" will be generated. But apparently, it throws de-serialization exception. </p>
  
  <p>We saw few articles and the suggestion was to do something like:</p>
  
  <pre><code> @Bean
    public ConsumerFactory&lt;String, Car&gt; consumerFactory() {
      return new DefaultKafkaConsumerFactory&lt;&gt;(consumerConfigs(), new StringDeserializer(),
          new JsonDeserializer&lt;&gt;(Car.class));
    }
  </code></pre>
  
  <p>We don't want to write some code for creating the Deserializer. Is there any boilerplate thing which we are missing?
  Any help will be appreciated!! </p>