From fc4ce885fca816234b76f126271d94a5db71a02d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Vannicatte?= Date: Wed, 11 May 2022 11:43:17 +0200 Subject: [PATCH] remove unused content type checking --- .../java/com/algolia/utils/HttpRequester.java | 17 +------- .../libraries/okhttp-gson/ApiClient.mustache | 40 ++++--------------- 2 files changed, 9 insertions(+), 48 deletions(-) diff --git a/clients/algoliasearch-client-java-2/algoliasearch-core/src/main/java/com/algolia/utils/HttpRequester.java b/clients/algoliasearch-client-java-2/algoliasearch-core/src/main/java/com/algolia/utils/HttpRequester.java index 5b60a89d1d..82c2cc9ffa 100644 --- a/clients/algoliasearch-client-java-2/algoliasearch-core/src/main/java/com/algolia/utils/HttpRequester.java +++ b/clients/algoliasearch-client-java-2/algoliasearch-core/src/main/java/com/algolia/utils/HttpRequester.java @@ -1,6 +1,5 @@ package com.algolia.utils; -import com.algolia.ApiClient; import com.algolia.exceptions.*; import com.algolia.utils.retry.RetryStrategy; import com.algolia.utils.retry.StatefulHost; @@ -99,20 +98,8 @@ private T deserialize(Response response, Type returnType) if (contentType == null) { contentType = "application/json"; } - if (ApiClient.isJsonMime(contentType)) { - return JSON.deserialize(respBody, returnType); - } else if (returnType.equals(String.class)) { - // Expecting string, return the raw response body. - return (T) respBody; - } else { - throw new AlgoliaApiException( - "Content type \"" + - contentType + - "\" is not supported for type: " + - returnType, - response.code() - ); - } + + return JSON.deserialize(respBody, returnType); } public void setDebugging(boolean debugging) { diff --git a/templates/java/libraries/okhttp-gson/ApiClient.mustache b/templates/java/libraries/okhttp-gson/ApiClient.mustache index ca1245ea3a..b0e3e16d97 100644 --- a/templates/java/libraries/okhttp-gson/ApiClient.mustache +++ b/templates/java/libraries/okhttp-gson/ApiClient.mustache @@ -194,22 +194,6 @@ public class ApiClient { } } - /** - * Check if the given MIME is a JSON MIME. - * JSON MIME examples: - * application/json - * application/json; charset=UTF8 - * APPLICATION/JSON - * application/vnd.company+json - * "* / *" is also default to JSON - * @param mime MIME (Multipurpose Internet Mail Extensions) - * @return True if the given MIME is JSON, false otherwise. - */ - public static boolean isJsonMime(String mime) { - String jsonMime = "(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$"; - return mime != null && (mime.matches(jsonMime) || mime.equals("*/*")); - } - /** * Escape the given string to be used as URL query value. * @@ -233,25 +217,15 @@ public class ApiClient { * @throws AlgoliaRuntimeException If fail to serialize the given object */ public RequestBody serialize(Object obj) throws AlgoliaRuntimeException { - if (obj instanceof byte[]) { - // Binary (byte array) body parameter support. - return RequestBody.create( - (byte[]) obj, - MediaType.parse(this.contentType) - ); - } else if (isJsonMime(this.contentType)) { - String content; - if (obj != null) { - content = JSON.serialize(obj); - } else { - content = null; - } - return RequestBody.create(content, MediaType.parse(this.contentType)); + String content; + + if (obj != null) { + content = JSON.serialize(obj); } else { - throw new AlgoliaRuntimeException( - "Content type \"" + this.contentType + "\" is not supported" - ); + content = null; } + + return RequestBody.create(content, MediaType.parse(this.contentType)); } /**