Skip to content

Commit

Permalink
Remove use of Pulsar ObjectMapperFactory
Browse files Browse the repository at this point in the history
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 spring-projects/spring-pulsar#562
  • Loading branch information
onobc committed Feb 3, 2024
1 parent cff9d46 commit d84d6f7
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@
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;
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;
Expand Down Expand Up @@ -87,7 +87,10 @@ private void customizeAuthentication(AuthenticationConsumer authentication,
private String getAuthenticationParamsJson(Map<String, String> params) {
Map<String, String> 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);
Expand Down

0 comments on commit d84d6f7

Please sign in to comment.