Skip to content

Kafka Streams: java.lang.IllegalArgumentException: Data should be null for a VoidDeserializer

I am working through my first sample of Kafka Streams:

package com.example;

import java.util.Properties;
import org.apache.kafka.clients.consumer.ConsumerConfig;
import org.apache.kafka.common.serialization.Serdes;
import org.apache.kafka.streams.KafkaStreams;
import org.apache.kafka.streams.StreamsBuilder;
import org.apache.kafka.streams.StreamsConfig;
import org.apache.kafka.streams.kstream.KStream;

class DslExample {

  public static void main(String[] args) {
    // the builder is used to construct the topology
    StreamsBuilder builder = new StreamsBuilder();

    // read from the source topic, "users"
    KStream<Void, String> stream ="users");

    // for each record that appears in the source topic,
    // print the value
        (key, value) -> {
          System.out.println("(DSL) Hello, " + value);

    // you can also print using the `print` operator
    // stream.print(Printed.<String, String>toSysOut().withLabel("source"));

    // set the required properties for running Kafka Streams
    Properties config = new Properties();
    config.put(StreamsConfig.APPLICATION_ID_CONFIG, "dev1");
    config.put(StreamsConfig.BOOTSTRAP_SERVERS_CONFIG, "");
    config.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest");
    config.put(StreamsConfig.DEFAULT_KEY_SERDE_CLASS_CONFIG, Serdes.Void().getClass());
    config.put(StreamsConfig.DEFAULT_VALUE_SERDE_CLASS_CONFIG, Serdes.String().getClass());

    // build the topology and start streaming
    KafkaStreams streams = new KafkaStreams(, config);

    // close Kafka Streams when the JVM shuts down (e.g. SIGTERM)
    Runtime.getRuntime().addShutdownHook(new Thread(streams::close));

When I attempt to run it I get this error:

Caused by: java.lang.IllegalArgumentException: Data should be null for a VoidDeserializer.

This is a sample message from the “users” topic:


  "registertime": 1517518703752,
  "userid": "User_8",
  "regionid": "Region_7",
  "gender": "OTHER"


    "key": "task.generation",
    "stringValue": "0"
    "key": "",
    "stringValue": "0"
    "key": "current.iteration",
    "stringValue": "86144"



What should I do to avoid this problem?


If the key actually has data, you shouldn’t be using Serdes.Void() or KStream<Void,