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
This commit is contained in:
Chris Bono 2024-02-03 00:29:45 -06:00 committed by Moritz Halbritter
parent 976152b244
commit 41ed4d6cf4
1 changed files with 5 additions and 2 deletions

View File

@ -23,6 +23,7 @@ import java.util.TreeMap;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.function.BiConsumer; import java.util.function.BiConsumer;
import java.util.function.Consumer; import java.util.function.Consumer;
import java.util.stream.Collectors;
import org.apache.pulsar.client.admin.PulsarAdminBuilder; import org.apache.pulsar.client.admin.PulsarAdminBuilder;
import org.apache.pulsar.client.api.ClientBuilder; 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.ProducerBuilder;
import org.apache.pulsar.client.api.PulsarClientException.UnsupportedAuthenticationException; import org.apache.pulsar.client.api.PulsarClientException.UnsupportedAuthenticationException;
import org.apache.pulsar.client.api.ReaderBuilder; import org.apache.pulsar.client.api.ReaderBuilder;
import org.apache.pulsar.common.util.ObjectMapperFactory;
import org.springframework.boot.context.properties.PropertyMapper; import org.springframework.boot.context.properties.PropertyMapper;
import org.springframework.pulsar.listener.PulsarContainerProperties; import org.springframework.pulsar.listener.PulsarContainerProperties;
@ -87,7 +87,10 @@ final class PulsarPropertiesMapper {
private String getAuthenticationParamsJson(Map<String, String> params) { private String getAuthenticationParamsJson(Map<String, String> params) {
Map<String, String> sortedParams = new TreeMap<>(params); Map<String, String> sortedParams = new TreeMap<>(params);
try { 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) { catch (Exception ex) {
throw new IllegalStateException("Could not convert auth parameters to encoded string", ex); throw new IllegalStateException("Could not convert auth parameters to encoded string", ex);