From: Kai Moritz Date: Fri, 18 Aug 2023 14:34:15 +0000 (+0200) Subject: NG X-Git-Tag: rebase--2023-08-18-abends~1 X-Git-Url: http://juplo.de/gitweb/?a=commitdiff_plain;h=5b84af870088bb4066afdfa5b77b81289acdbee6;p=demos%2Fkafka%2Fchat NG --- 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) {