[java][okhttp-gson] minor improvements (#13792)

* use replace instead of replaceAll

* avoid using instance to accessd static methods

* use entrySet instead of keySet

* use statis class instead of instance for static method

* update samples
This commit is contained in:
William Cheng
2022-10-22 13:31:59 +08:00
committed by GitHub
parent 2e4a02532e
commit ca56242e4f
19 changed files with 103 additions and 103 deletions

View File

@@ -371,7 +371,7 @@ public class ApiClient {
* @return a {@link org.openapitools.client.ApiClient} object
*/
public ApiClient setDateFormat(DateFormat dateFormat) {
this.json.setDateFormat(dateFormat);
JSON.setDateFormat(dateFormat);
return this;
}
@@ -382,7 +382,7 @@ public class ApiClient {
* @return a {@link org.openapitools.client.ApiClient} object
*/
public ApiClient setSqlDateFormat(DateFormat dateFormat) {
this.json.setSqlDateFormat(dateFormat);
JSON.setSqlDateFormat(dateFormat);
return this;
}
@@ -393,7 +393,7 @@ public class ApiClient {
* @return a {@link org.openapitools.client.ApiClient} object
*/
public ApiClient setOffsetDateTimeFormat(DateTimeFormatter dateFormat) {
this.json.setOffsetDateTimeFormat(dateFormat);
JSON.setOffsetDateTimeFormat(dateFormat);
return this;
}
@@ -404,7 +404,7 @@ public class ApiClient {
* @return a {@link org.openapitools.client.ApiClient} object
*/
public ApiClient setLocalDateFormat(DateTimeFormatter dateFormat) {
this.json.setLocalDateFormat(dateFormat);
JSON.setLocalDateFormat(dateFormat);
return this;
}
@@ -415,7 +415,7 @@ public class ApiClient {
* @return a {@link org.openapitools.client.ApiClient} object
*/
public ApiClient setLenientOnJson(boolean lenientOnJson) {
this.json.setLenientOnJson(lenientOnJson);
JSON.setLenientOnJson(lenientOnJson);
return this;
}
@@ -696,7 +696,7 @@ public class ApiClient {
return "";
} else if (param instanceof Date || param instanceof OffsetDateTime || param instanceof LocalDate) {
//Serialize to json string and remove the " enclosing characters
String jsonStr = json.serialize(param);
String jsonStr = JSON.serialize(param);
return jsonStr.substring(1, jsonStr.length() - 1);
} else if (param instanceof Collection) {
StringBuilder b = new StringBuilder();
@@ -943,7 +943,7 @@ public class ApiClient {
contentType = "application/json";
}
if (isJsonMime(contentType)) {
return json.deserialize(respBody, returnType);
return JSON.deserialize(respBody, returnType);
} else if (returnType.equals(String.class)) {
// Expecting string, return the raw response body.
return (T) respBody;
@@ -977,7 +977,7 @@ public class ApiClient {
} else if (isJsonMime(contentType)) {
String content;
if (obj != null) {
content = json.serialize(obj);
content = JSON.serialize(obj);
} else {
content = null;
}
@@ -1456,7 +1456,7 @@ public class ApiClient {
} else {
String content;
if (obj != null) {
content = json.serialize(obj);
content = JSON.serialize(obj);
} else {
content = null;
}
@@ -1608,7 +1608,7 @@ public class ApiClient {
if (entry.getKey().equals(param.getName())) {
switch (param.getIn()) {
case "path":
path = path.replaceAll("\\{" + param.getName() + "\\}", escapeString(value.toString()));
path = path.replace("{" + param.getName() + "}", escapeString(value.toString()));
break;
case "query":
if (value instanceof Collection<?>) {

View File

@@ -65,8 +65,8 @@ public class RetryingOAuth extends OAuth implements Interceptor {
.setClientSecret(clientSecret));
setFlow(flow);
if (parameters != null) {
for (String paramName : parameters.keySet()) {
tokenRequestBuilder.setParameter(paramName, parameters.get(paramName));
for (Map.Entry<String, String> entry : parameters.entrySet()) {
tokenRequestBuilder.setParameter(entry.getKey(), entry.getValue());
}
}
}
@@ -129,8 +129,8 @@ public class RetryingOAuth extends OAuth implements Interceptor {
}
Map<String, String> headers = oAuthRequest.getHeaders();
for (String headerName : headers.keySet()) {
requestBuilder.addHeader(headerName, headers.get(headerName));
for (Map.Entry<String, String> entry : headers.entrySet()) {
requestBuilder.addHeader(entry.getKey(), entry.getValue());
}
requestBuilder.url(oAuthRequest.getLocationUri());