NG
authorKai Moritz <kai@juplo.de>
Fri, 18 Aug 2023 14:34:15 +0000 (16:34 +0200)
committerKai Moritz <kai@juplo.de>
Fri, 18 Aug 2023 15:18:41 +0000 (17:18 +0200)
src/main/java/de/juplo/kafka/chat/backend/persistence/kafka/KafkaServicesConfiguration.java

index af8c0aa..edc52bb 100644 (file)
@@ -97,13 +97,12 @@ public class KafkaServicesConfiguration
   }
 
   @Bean
-  JsonSerializer<AbstractTo> chatMessageSerializer()
+  JsonSerializer<AbstractTo> chatMessageSerializer(String typeMappings)
   {
     JsonSerializer<AbstractTo> serializer = new JsonSerializer<>();
     serializer.configure(
-        Map.of(JsonSerializer.TYPE_MAPPINGS,
-            "create:" + CreateChatRoomRequestTo.class.getCanonicalName() + "," +
-            "message:" + ChatMessageTo.class.getCanonicalName()),
+        Map.of(
+            JsonSerializer.TYPE_MAPPINGS, typeMappings),
         false);
     return serializer;
   }
@@ -136,15 +135,25 @@ public class KafkaServicesConfiguration
   }
 
   @Bean
-  JsonDeserializer<AbstractTo> chatMessageDeserializer()
+  JsonDeserializer<AbstractTo> chatMessageDeserializer(String typeMappings)
   {
     JsonDeserializer<AbstractTo> deserializer = new JsonDeserializer<>();
     deserializer.configure(
-        Map.of(JsonDeserializer.TRUSTED_PACKAGES, getClass().getPackageName()),
+        Map.of(
+            JsonDeserializer.TRUSTED_PACKAGES, getClass().getPackageName(),
+            JsonDeserializer.TYPE_MAPPINGS, typeMappings),
         false );
     return deserializer;
   }
 
+  @Bean
+  String typeMappings ()
+  {
+    return
+        "create:" +  CreateChatRoomRequestTo.class.getCanonicalName() + "," +
+        "message:" + ChatMessageTo.class.getCanonicalName();
+  }
+
   @Bean
   Properties defaultProducerProperties(ChatBackendProperties chatBackendProperties)
   {