From 5b84af870088bb4066afdfa5b77b81289acdbee6 Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Fri, 18 Aug 2023 16:34:15 +0200 Subject: [PATCH] NG --- .../kafka/KafkaServicesConfiguration.java | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/main/java/de/juplo/kafka/chat/backend/persistence/kafka/KafkaServicesConfiguration.java b/src/main/java/de/juplo/kafka/chat/backend/persistence/kafka/KafkaServicesConfiguration.java index af8c0aad..edc52bb0 100644 --- a/src/main/java/de/juplo/kafka/chat/backend/persistence/kafka/KafkaServicesConfiguration.java +++ b/src/main/java/de/juplo/kafka/chat/backend/persistence/kafka/KafkaServicesConfiguration.java @@ -97,13 +97,12 @@ public class KafkaServicesConfiguration } @Bean - JsonSerializer chatMessageSerializer() + JsonSerializer chatMessageSerializer(String typeMappings) { JsonSerializer 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 chatMessageDeserializer() + JsonDeserializer chatMessageDeserializer(String typeMappings) { JsonDeserializer 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) { -- 2.20.1