From 41ed4d6cf4c5e316f236c99ce59cf7ddfa48ee89 Mon Sep 17 00:00:00 2001 From: Chris Bono Date: Sat, 3 Feb 2024 00:29:45 -0600 Subject: [PATCH] Remove use of Pulsar ObjectMapperFactory This commit removes the use of the Pulsar ObjectMapperFactory when converting the authentication config props map to a JSON string. The Pulsar factory operates on a shaded returned value of Jackson ObjectMapper which may not exist when users are using the non-shaded version of the Pulsar client lib. See https://github.com/spring-projects/spring-pulsar/issues/562 See gh-39389 --- .../boot/autoconfigure/pulsar/PulsarPropertiesMapper.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/pulsar/PulsarPropertiesMapper.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/pulsar/PulsarPropertiesMapper.java index ed9411512eb..7b76c555022 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/pulsar/PulsarPropertiesMapper.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/pulsar/PulsarPropertiesMapper.java @@ -23,6 +23,7 @@ import java.util.TreeMap; import java.util.concurrent.TimeUnit; import java.util.function.BiConsumer; import java.util.function.Consumer; +import java.util.stream.Collectors; import org.apache.pulsar.client.admin.PulsarAdminBuilder; import org.apache.pulsar.client.api.ClientBuilder; @@ -30,7 +31,6 @@ import org.apache.pulsar.client.api.ConsumerBuilder; import org.apache.pulsar.client.api.ProducerBuilder; import org.apache.pulsar.client.api.PulsarClientException.UnsupportedAuthenticationException; import org.apache.pulsar.client.api.ReaderBuilder; -import org.apache.pulsar.common.util.ObjectMapperFactory; import org.springframework.boot.context.properties.PropertyMapper; import org.springframework.pulsar.listener.PulsarContainerProperties; @@ -87,7 +87,10 @@ final class PulsarPropertiesMapper { private String getAuthenticationParamsJson(Map params) { Map sortedParams = new TreeMap<>(params); try { - return ObjectMapperFactory.create().writeValueAsString(sortedParams); + return sortedParams.entrySet() + .stream() + .map((e) -> "\"%s\":\"%s\"".formatted(e.getKey(), e.getValue())) + .collect(Collectors.joining(",", "{", "}")); } catch (Exception ex) { throw new IllegalStateException("Could not convert auth parameters to encoded string", ex);