query: 2.0.0 - (GREEN) Values are serialized as JSON
[demos/kafka/wordcount] / src / main / java / de / juplo / kafka / wordcount / query / QueryApplicationConfiguration.java
index 50a5364..7da1712 100644 (file)
@@ -1,6 +1,5 @@
 package de.juplo.kafka.wordcount.query;
 
-import com.fasterxml.jackson.databind.ObjectMapper;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.kafka.clients.consumer.ConsumerConfig;
 import org.apache.kafka.common.serialization.Serdes;
@@ -14,6 +13,8 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties
 import org.springframework.context.ConfigurableApplicationContext;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
+import org.springframework.kafka.support.serializer.JsonDeserializer;
+import org.springframework.kafka.support.serializer.JsonSerde;
 
 import java.io.IOException;
 import java.net.InetSocketAddress;
@@ -78,7 +79,14 @@ public class QueryApplicationConfiguration
                Properties props = new Properties();
 
                props.put(StreamsConfig.DEFAULT_KEY_SERDE_CLASS_CONFIG, Serdes.String().getClass().getName());
-               props.put(StreamsConfig.DEFAULT_VALUE_SERDE_CLASS_CONFIG, Serdes.String().getClass().getName());
+               props.put(StreamsConfig.DEFAULT_VALUE_SERDE_CLASS_CONFIG, JsonSerde.class.getName());
+               props.put(JsonDeserializer.VALUE_DEFAULT_TYPE, User.class.getName()); // << Does not work without this!
+               props.put(
+                               JsonDeserializer.TYPE_MAPPINGS,
+                               "user:" + Key.class.getName() + "," +
+                               "ranking:" + Ranking.class.getName() + "," +
+                               "userdata:" + User.class.getName() + "," +
+                               "userranking:" + UserRanking.class.getName());
 
                return props;
        }
@@ -89,7 +97,6 @@ public class QueryApplicationConfiguration
                        HostInfo applicationServer,
                        QueryApplicationProperties applicationProperties,
                        KeyValueBytesStoreSupplier storeSupplier,
-                       ObjectMapper mapper,
                        ConfigurableApplicationContext context)
        {
                QueryStreamProcessor streamProcessor = new QueryStreamProcessor(
@@ -97,8 +104,7 @@ public class QueryApplicationConfiguration
                                applicationServer,
                                applicationProperties.getUsersInputTopic(),
                                applicationProperties.getRankingInputTopic(),
-                               storeSupplier,
-                               mapper);
+                               storeSupplier);
 
                streamProcessor.streams.setUncaughtExceptionHandler((Throwable e) ->
                {