counter: 1.3.0 - (GREEN) Fixed the typing for the state-store
[demos/kafka/wordcount] / src / main / java / de / juplo / kafka / wordcount / counter / CounterStreamProcessor.java
index fd5c5a7..64bd619 100644 (file)
@@ -7,6 +7,7 @@ import org.apache.kafka.streams.kstream.Materialized;
 import org.apache.kafka.streams.state.KeyValueBytesStoreSupplier;
 import org.apache.kafka.streams.state.QueryableStoreTypes;
 import org.apache.kafka.streams.state.ReadOnlyKeyValueStore;
+import org.springframework.kafka.support.serializer.JsonSerde;
 
 import java.util.Properties;
 
@@ -46,7 +47,10 @@ public class CounterStreamProcessor
                source
                                .map((key, word) -> new KeyValue<>(word, word))
                                .groupByKey()
-                               .count(Materialized.as(storeSupplier))
+                               .count(
+                                               Materialized
+                                                               .<Word, Long>as(storeSupplier)
+                                                               .withKeySerde(new JsonSerde<>().copyWithType(Word.class).forKeys()))
                                .toStream()
                                .map((word, counter) -> new KeyValue<>(word, WordCounter.of(word, counter)))
                                .to(outputTopic);