From 90ad80b97ddbbc9c81694d24c77375aff2352253 Mon Sep 17 00:00:00 2001 From: Steve Hawkins Date: Sun, 11 Dec 2022 08:50:30 -0500 Subject: [PATCH] fix #3972 encapsulated / deprecated usage of static json/yaml mappers --- CHANGELOG.md | 2 +- .../cache/ReducedStateItemStore.java | 4 +- .../client/internal/KubeConfigUtils.java | 11 +++-- .../kubernetes/client/utils/IOHelpers.java | 20 +++++---- .../client/utils/Serialization.java | 41 ++++++++++++++++++- .../dsl/internal/AbstractWatchManager.java | 8 ++-- .../client/dsl/internal/BaseOperation.java | 6 +-- .../client/dsl/internal/OperationSupport.java | 31 +++----------- .../internal/core/v1/PodOperationsImpl.java | 3 +- .../build/BuildConfigOperationsImpl.java | 10 ++--- .../internal/OpenShiftOAuthInterceptor.java | 6 +-- 11 files changed, 79 insertions(+), 63 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 39ee7dcb588..daff8148808 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,7 +35,7 @@ * Fix #4597: remove the deprecated support for `javax.validation.constraints.NotNull` in the `crd-generator`, to mark a property as `required` it needs to be annotated with `io.fabric8.generator.annotation.Required` * Fix #3973: removed support for Parameterizable - that was only needed as a workaround for non-string parameters. You should instead include those parameter values in the map passed to processLocally. * Fix #3973: openShiftClient.templates().load and openShiftClient.load will no longer automatically process / create templates. Use the method openshiftClient.templates().from to get a template from any stream. -* Fix #3973: deprecated Serialization methods that take parameters. +* Fix #3973: deprecated Serialization methods that take parameters and methods for the json and yaml mappers. ### 6.2.0 (2022-10-20) diff --git a/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/informers/cache/ReducedStateItemStore.java b/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/informers/cache/ReducedStateItemStore.java index 951c1438bee..14fc2be6e3e 100644 --- a/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/informers/cache/ReducedStateItemStore.java +++ b/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/informers/cache/ReducedStateItemStore.java @@ -116,7 +116,7 @@ Object[] store(V value) { if (value == null) { return null; } - Map raw = Serialization.jsonMapper().convertValue(value, Map.class); + Map raw = Serialization.convertValue(value, Map.class); return fields.stream().map(f -> GenericKubernetesResource.get(raw, (Object[]) f)).toArray(); } @@ -129,7 +129,7 @@ V restore(String key, Object[] values) { String[] keyParts = this.keyState.keyFieldFunction.apply(key); applyFields(keyParts, raw, this.keyState.keyFields); - return Serialization.jsonMapper().convertValue(raw, typeClass); + return Serialization.convertValue(raw, typeClass); } private static void applyFields(Object[] values, Map raw, List fields) { diff --git a/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/internal/KubeConfigUtils.java b/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/internal/KubeConfigUtils.java index 7d5a53383f9..9a1013c01ff 100644 --- a/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/internal/KubeConfigUtils.java +++ b/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/internal/KubeConfigUtils.java @@ -15,7 +15,6 @@ */ package io.fabric8.kubernetes.client.internal; -import com.fasterxml.jackson.databind.ObjectMapper; import io.fabric8.kubernetes.api.model.AuthInfo; import io.fabric8.kubernetes.api.model.Cluster; import io.fabric8.kubernetes.api.model.Config; @@ -23,9 +22,11 @@ import io.fabric8.kubernetes.api.model.NamedAuthInfo; import io.fabric8.kubernetes.api.model.NamedCluster; import io.fabric8.kubernetes.api.model.NamedContext; +import io.fabric8.kubernetes.client.utils.IOHelpers; import io.fabric8.kubernetes.client.utils.Serialization; import java.io.File; +import java.io.FileInputStream; import java.io.IOException; import java.util.List; @@ -39,13 +40,11 @@ private KubeConfigUtils() { } public static Config parseConfig(File file) throws IOException { - ObjectMapper mapper = Serialization.yamlMapper(); - return mapper.readValue(file, Config.class); + return Serialization.unmarshal(new FileInputStream(file), Config.class); } public static Config parseConfigFromString(String contents) throws IOException { - ObjectMapper mapper = Serialization.yamlMapper(); - return mapper.readValue(contents, Config.class); + return Serialization.unmarshal(contents, Config.class); } /** @@ -158,6 +157,6 @@ public static int getNamedUserIndexFromConfig(Config config, String userName) { * @throws IOException in case of failure while writing to file */ public static void persistKubeConfigIntoFile(Config kubeConfig, String kubeConfigPath) throws IOException { - Serialization.yamlMapper().writeValue(new File(kubeConfigPath), kubeConfig); + IOHelpers.write(Serialization.asYaml(kubeConfig), kubeConfigPath); } } diff --git a/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/utils/IOHelpers.java b/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/utils/IOHelpers.java index e51978245ad..7d9fdad3df7 100644 --- a/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/utils/IOHelpers.java +++ b/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/utils/IOHelpers.java @@ -19,6 +19,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import java.io.BufferedReader; +import java.io.FileWriter; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; @@ -64,6 +65,10 @@ private static void copy(Reader reader, Writer writer) throws IOException { } } + /** + * @deprecated to be removed in future versions + */ + @Deprecated public static boolean isJSONValid(String json) { try { ObjectMapper objectMapper = Serialization.jsonMapper(); @@ -75,18 +80,17 @@ public static boolean isJSONValid(String json) { } public static String convertYamlToJson(String yaml) throws IOException { - ObjectMapper yamlReader = Serialization.yamlMapper(); - Object obj = yamlReader.readValue(yaml, Object.class); - - ObjectMapper jsonWriter = Serialization.jsonMapper(); - return jsonWriter.writeValueAsString(obj); + return Serialization.asJson(Serialization.unmarshal(yaml, Object.class)); } public static String convertToJson(String jsonOrYaml) throws IOException { - if (isJSONValid(jsonOrYaml)) { - return jsonOrYaml; - } return convertYamlToJson(jsonOrYaml); } + public static void write(String asYaml, String kubeConfigPath) throws IOException { + try (FileWriter writer = new FileWriter(kubeConfigPath)) { + writer.write(asYaml); + } + } + } diff --git a/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/utils/Serialization.java b/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/utils/Serialization.java index c4d06311421..9fb899fb85a 100644 --- a/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/utils/Serialization.java +++ b/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/utils/Serialization.java @@ -27,6 +27,8 @@ import io.fabric8.kubernetes.client.KubernetesClientException; import io.fabric8.kubernetes.model.jackson.UnmatchedFieldTypeModule; import org.yaml.snakeyaml.DumperOptions; +import org.yaml.snakeyaml.DumperOptions.FlowStyle; +import org.yaml.snakeyaml.LoaderOptions; import org.yaml.snakeyaml.Yaml; import org.yaml.snakeyaml.constructor.SafeConstructor; import org.yaml.snakeyaml.nodes.Tag; @@ -75,7 +77,10 @@ private Serialization() { * n.b. the use of this module gives precedence to properties present in the additionalProperties Map present * in most KubernetesResource instances. If a property is both defined in the Map and in the original field, the * one from the additionalProperties Map will be serialized. + * + * @deprecated */ + @Deprecated public static ObjectMapper jsonMapper() { return JSON_MAPPER; } @@ -92,7 +97,10 @@ public static ObjectMapper jsonMapper() { * n.b. the use of this module gives precedence to properties present in the additionalProperties Map present * in most KubernetesResource instances. If a property is both defined in the Map and in the original field, the * one from the additionalProperties Map will be serialized. + * + * @deprecated will be removed in future versions */ + @Deprecated public static ObjectMapper yamlMapper() { if (YAML_MAPPER == null) { synchronized (Serialization.class) { @@ -111,7 +119,10 @@ public static ObjectMapper yamlMapper() { * This is useful because in a lot of cases the YAML mapper is only need at application startup * when the client is created, so there is no reason to keep the very heavy (in terms of memory) mapper * around indefinitely. + * + * @deprecated */ + @Deprecated public static void clearYamlMapper() { YAML_MAPPER = null; } @@ -154,6 +165,15 @@ public static String asYaml(T object) { } catch (JsonProcessingException e) { throw KubernetesClientException.launderThrowable(e); } + /* + * TODO: this will bypass the need for a yamlMapper + * Yaml yaml = yaml(); + * try { + * return yaml.dump(convertValue(object, Map.class)); + * } catch (IllegalArgumentException e) { + * return yaml.dump(convertValue(convertValue(object, JsonNode.class), Object.class)); + * } + */ } /** @@ -254,8 +274,7 @@ private static T unmarshal(InputStream is, ObjectMapper mapper, TypeReferenc final T result; if (intch != '{' && intch != '[') { - final Yaml yaml = new Yaml(new SafeConstructor(), new Representer(), new DumperOptions(), - new CustomYamlTagResolverWithLimit()); + Yaml yaml = yaml(); final Object obj = yaml.load(bis); if (obj instanceof Map) { result = mapper.convertValue(obj, type); @@ -271,6 +290,16 @@ private static T unmarshal(InputStream is, ObjectMapper mapper, TypeReferenc } } + private static Yaml yaml() { + LoaderOptions loaderOptions = new LoaderOptions(); + DumperOptions dumperOptions = new DumperOptions(); + dumperOptions.setExplicitStart(true); + dumperOptions.setDefaultFlowStyle(FlowStyle.BLOCK); + Yaml yaml = new Yaml(new SafeConstructor(loaderOptions), new Representer(dumperOptions), dumperOptions, + loaderOptions, new CustomYamlTagResolverWithLimit()); + return yaml; + } + /** * Unmarshals a {@link String} *

@@ -452,4 +481,12 @@ public void addImplicitResolver(Tag tag, Pattern regexp, String first, int limit super.addImplicitResolver(tag, regexp, first, limit); } } + + public static T convertValue(Object value, Class type) { + return JSON_MAPPER.convertValue(value, type); + } + + public static Type constructParametricType(Class parameterizedClass, Class parameterType) { + return JSON_MAPPER.getTypeFactory().constructParametricType(parameterizedClass, parameterType); + } } diff --git a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/AbstractWatchManager.java b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/AbstractWatchManager.java index c923872640f..eecfb40a508 100644 --- a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/AbstractWatchManager.java +++ b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/AbstractWatchManager.java @@ -183,7 +183,7 @@ void eventReceived(Watcher.Action action, HasMetadata resource) { // the WatchEvent deserialization is not specifically typed // modify the type here if needed if (resource != null && !baseOperation.getType().isAssignableFrom(resource.getClass())) { - resource = Serialization.jsonMapper().convertValue(resource, baseOperation.getType()); + resource = Serialization.convertValue(resource, baseOperation.getType()); } @SuppressWarnings("unchecked") final T t = (T) resource; @@ -234,14 +234,14 @@ private WatchEvent contextAwareWatchEventDeserializer(String messageSource) try { return Serialization.unmarshal(messageSource, WatchEvent.class); } catch (Exception ex1) { - JsonNode json = Serialization.jsonMapper().readTree(messageSource); + JsonNode json = Serialization.unmarshal(messageSource, JsonNode.class); JsonNode objectJson = null; if (json instanceof ObjectNode && json.has("object")) { objectJson = ((ObjectNode) json).remove("object"); } - WatchEvent watchEvent = Serialization.jsonMapper().treeToValue(json, WatchEvent.class); - KubernetesResource object = Serialization.jsonMapper().treeToValue(objectJson, baseOperation.getType()); + WatchEvent watchEvent = Serialization.convertValue(json, WatchEvent.class); + KubernetesResource object = Serialization.convertValue(objectJson, baseOperation.getType()); watchEvent.setObject(object); return watchEvent; diff --git a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/BaseOperation.java b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/BaseOperation.java index b4e99c23f58..7662bd20eac 100755 --- a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/BaseOperation.java +++ b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/BaseOperation.java @@ -249,7 +249,7 @@ public BaseOperation inAnyNamespace() { @Override public R load(InputStream is) { - T unmarshal = unmarshal(is, type); + T unmarshal = Serialization.unmarshal(is, type); // if you do something like client.foo().v2().load(v1 resource) // it will parse as v2, but have a v1 apiVersion, so we need to // force the apiVersion @@ -394,7 +394,7 @@ public CompletableFuture submitList(ListOptions listOptions) { URL fetchListUrl = fetchListUrl(getNamespacedUrl(), defaultListOptions(listOptions, null)); HttpRequest.Builder requestBuilder = httpClient.newHttpRequestBuilder().url(fetchListUrl); Type refinedType = listType.equals(DefaultKubernetesResourceList.class) - ? Serialization.jsonMapper().getTypeFactory().constructParametricType(listType, type) + ? Serialization.constructParametricType(listType, type) : listType; TypeReference listTypeReference = new TypeReference() { @Override @@ -740,7 +740,7 @@ public X operation(Scope scope, String operation, String method, Object payl HttpRequest.Builder requestBuilder = httpClient.newHttpRequestBuilder() .uri(baseUrl + "/" + operation); if (payload != null) { - requestBuilder.method(method, JSON, JSON_MAPPER.writeValueAsString(payload)); + requestBuilder.method(method, JSON, Serialization.asJson(payload)); } return handleResponse(requestBuilder, responseType); } catch (IOException e) { diff --git a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/OperationSupport.java b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/OperationSupport.java index dcc6a0fcef4..9c4a9a7dcbd 100644 --- a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/OperationSupport.java +++ b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/OperationSupport.java @@ -16,7 +16,6 @@ package io.fabric8.kubernetes.client.dsl.internal; import com.fasterxml.jackson.core.type.TypeReference; -import com.fasterxml.jackson.databind.ObjectMapper; import io.fabric8.kubernetes.api.model.DeleteOptions; import io.fabric8.kubernetes.api.model.DeletionPropagation; import io.fabric8.kubernetes.api.model.HasMetadata; @@ -44,7 +43,6 @@ import java.io.ByteArrayInputStream; import java.io.IOException; -import java.io.InputStream; import java.io.InterruptedIOException; import java.lang.reflect.Type; import java.net.HttpURLConnection; @@ -53,7 +51,6 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; -import java.util.Map; import java.util.Objects; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; @@ -67,7 +64,6 @@ public class OperationSupport { public static final String STRATEGIC_MERGE_JSON_PATCH = "application/strategic-merge-patch+json"; public static final String JSON_MERGE_PATCH = "application/merge-patch+json"; - protected static final ObjectMapper JSON_MAPPER = Serialization.jsonMapper(); private static final Logger LOG = LoggerFactory.getLogger(OperationSupport.class); private static final String CLIENT_STATUS_FLAG = "CLIENT_STATUS_FLAG"; private static final int MAX_RETRY_INTERVAL_EXPONENT = 5; @@ -322,7 +318,7 @@ protected KubernetesResource handleDelete(URL requestUrl, long gracePeriodSecond } HttpRequest.Builder requestBuilder = httpClient.newHttpRequestBuilder() - .delete(JSON, JSON_MAPPER.writeValueAsString(deleteOptions)).url(requestUrl); + .delete(JSON, Serialization.asJson(deleteOptions)).url(requestUrl); return handleResponse(requestBuilder, KubernetesResource.class); } @@ -342,7 +338,7 @@ protected KubernetesResource handleDelete(URL requestUrl, long gracePeriodSecond protected T handleCreate(I resource, Class outputType) throws InterruptedException, IOException { resource = correctNamespace(resource); HttpRequest.Builder requestBuilder = httpClient.newHttpRequestBuilder() - .post(JSON, JSON_MAPPER.writeValueAsString(resource)) + .post(JSON, Serialization.asJson(resource)) .url(getResourceURLForWriteOperation(getResourceUrl(checkNamespace(resource), null))); return handleResponse(requestBuilder, outputType); } @@ -361,7 +357,7 @@ protected T handleCreate(I resource, Class outputType) throws Interrup protected T handleUpdate(T updated, Class type, boolean status) throws IOException { updated = correctNamespace(updated); HttpRequest.Builder requestBuilder = httpClient.newHttpRequestBuilder() - .put(JSON, JSON_MAPPER.writeValueAsString(updated)) + .put(JSON, Serialization.asJson(updated)) .url(getResourceURLForWriteOperation(getResourceUrl(checkNamespace(updated), checkName(updated), status))); return handleResponse(requestBuilder, type); } @@ -451,7 +447,7 @@ protected T handleGet(URL resourceUrl, Class type) throws IOException { protected T handleApproveOrDeny(T csr, Class type) throws IOException, InterruptedException { String uri = URLUtils.join(getResourceUrl(null, csr.getMetadata().getName(), false).toString(), "approval"); HttpRequest.Builder requestBuilder = httpClient.newHttpRequestBuilder() - .put(JSON, JSON_MAPPER.writeValueAsString(csr)).uri(uri); + .put(JSON, Serialization.asJson(csr)).uri(uri); return handleResponse(requestBuilder, type); } @@ -637,7 +633,7 @@ public static Status createStatus(HttpResponse response) { try { String bodyString = response.bodyString(); if (Utils.isNotNullOrEmpty(bodyString)) { - Status status = JSON_MAPPER.readValue(bodyString, Status.class); + Status status = Serialization.unmarshal(bodyString, Status.class); if (status.getCode() == null) { status = new StatusBuilder(status).withCode(statusCode).build(); } @@ -703,23 +699,6 @@ public static KubernetesClientException requestException(HttpRequest request, Ex return requestException(request, e, null); } - protected static T unmarshal(InputStream is) { - return Serialization.unmarshal(is); - } - - protected static T unmarshal(InputStream is, final Class type) { - return Serialization.unmarshal(is, type); - } - - protected static T unmarshal(InputStream is, TypeReference type) { - return Serialization.unmarshal(is, type); - } - - protected static Map getObjectValueAsMap(T object) { - return JSON_MAPPER.convertValue(object, new TypeReference>() { - }); - } - public Config getConfig() { return config; } diff --git a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/core/v1/PodOperationsImpl.java b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/core/v1/PodOperationsImpl.java index 4ad949e7092..2ec347901d3 100644 --- a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/core/v1/PodOperationsImpl.java +++ b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/core/v1/PodOperationsImpl.java @@ -55,6 +55,7 @@ import io.fabric8.kubernetes.client.http.HttpRequest; import io.fabric8.kubernetes.client.http.WebSocket; import io.fabric8.kubernetes.client.lib.FilenameUtils; +import io.fabric8.kubernetes.client.utils.Serialization; import io.fabric8.kubernetes.client.utils.URLUtils; import io.fabric8.kubernetes.client.utils.URLUtils.URLBuilder; import io.fabric8.kubernetes.client.utils.Utils; @@ -253,7 +254,7 @@ private boolean handleEvict(HasMetadata eviction) { URL requestUrl = new URL(URLUtils.join(getResourceUrl().toString(), "eviction")); HttpRequest.Builder requestBuilder = httpClient.newHttpRequestBuilder() - .post(JSON, JSON_MAPPER.writeValueAsString(eviction)).url(requestUrl); + .post(JSON, Serialization.asJson(eviction)).url(requestUrl); handleResponse(requestBuilder, null); return true; } catch (KubernetesClientException e) { diff --git a/openshift-client/src/main/java/io/fabric8/openshift/client/dsl/internal/build/BuildConfigOperationsImpl.java b/openshift-client/src/main/java/io/fabric8/openshift/client/dsl/internal/build/BuildConfigOperationsImpl.java index 71c36897e2c..17fa1d10e69 100644 --- a/openshift-client/src/main/java/io/fabric8/openshift/client/dsl/internal/build/BuildConfigOperationsImpl.java +++ b/openshift-client/src/main/java/io/fabric8/openshift/client/dsl/internal/build/BuildConfigOperationsImpl.java @@ -25,10 +25,10 @@ import io.fabric8.kubernetes.client.dsl.internal.HasMetadataOperation; import io.fabric8.kubernetes.client.dsl.internal.HasMetadataOperationsImpl; import io.fabric8.kubernetes.client.dsl.internal.OperationContext; -import io.fabric8.kubernetes.client.dsl.internal.OperationSupport; import io.fabric8.kubernetes.client.http.HttpClient; import io.fabric8.kubernetes.client.http.HttpRequest; import io.fabric8.kubernetes.client.utils.KubernetesResourceUtil; +import io.fabric8.kubernetes.client.utils.Serialization; import io.fabric8.kubernetes.client.utils.URLUtils; import io.fabric8.kubernetes.client.utils.Utils; import io.fabric8.openshift.api.model.Build; @@ -54,7 +54,6 @@ import java.io.InputStream; import java.lang.reflect.Type; import java.net.MalformedURLException; -import java.net.URL; import java.util.List; import java.util.concurrent.TimeUnit; @@ -113,10 +112,7 @@ public BuildConfigOperationContext getContext() { public Build instantiate(BuildRequest request) { try { updateApiVersion(request); - URL instantiationUrl = new URL(URLUtils.join(getResourceUrl().toString(), "instantiate")); - HttpRequest.Builder requestBuilder = this.httpClient.newHttpRequestBuilder() - .post(JSON, OperationSupport.JSON_MAPPER.writer().writeValueAsString(request)).url(instantiationUrl); - return handleResponse(requestBuilder, Build.class); + return this.operation(Scope.RESOURCE, "instantiate", "POST", request, Build.class); } catch (Exception e) { throw KubernetesClientException.launderThrowable(e); } @@ -133,7 +129,7 @@ public Void trigger(WebHookTrigger trigger) { //TODO: This needs some attention. String triggerUrl = URLUtils.join(getResourceUrl().toString(), "webhooks", secret, triggerType); HttpRequest.Builder requestBuilder = this.httpClient.newHttpRequestBuilder() - .post(JSON, OperationSupport.JSON_MAPPER.writer().writeValueAsBytes(trigger)) + .post(JSON, Serialization.asJson(trigger)) .uri(triggerUrl) .header("X-Github-Event", "push"); handleResponse(requestBuilder, null); diff --git a/openshift-client/src/main/java/io/fabric8/openshift/client/internal/OpenShiftOAuthInterceptor.java b/openshift-client/src/main/java/io/fabric8/openshift/client/internal/OpenShiftOAuthInterceptor.java index 95c67ba016d..ad02a625dd5 100644 --- a/openshift-client/src/main/java/io/fabric8/openshift/client/internal/OpenShiftOAuthInterceptor.java +++ b/openshift-client/src/main/java/io/fabric8/openshift/client/internal/OpenShiftOAuthInterceptor.java @@ -16,7 +16,6 @@ package io.fabric8.openshift.client.internal; -import com.fasterxml.jackson.databind.JsonNode; import io.fabric8.kubernetes.api.model.HasMetadata; import io.fabric8.kubernetes.api.model.authorization.v1.SelfSubjectAccessReview; import io.fabric8.kubernetes.client.Config; @@ -46,6 +45,7 @@ import java.util.Collections; import java.util.HashSet; import java.util.List; +import java.util.Map; import java.util.Set; import java.util.concurrent.CompletableFuture; import java.util.concurrent.atomic.AtomicReference; @@ -150,8 +150,8 @@ private CompletableFuture authorize() { String body = response.body(); try { - JsonNode jsonResponse = Serialization.jsonMapper().readTree(body); - String authorizationServer = jsonResponse.get("authorization_endpoint").asText(); + Map jsonResponse = Serialization.unmarshal(body, Map.class); + String authorizationServer = String.valueOf(jsonResponse.get("authorization_endpoint")); URL authorizeQuery = new URL(authorizationServer + AUTHORIZE_QUERY); String credential = HttpClientUtils.basicCredentials(config.getUsername(), config.getPassword());