Skip to content

Commit 47bd3e3

Browse files
Merge pull request #9 from avadev/jwenger/issue-fixes
Jwenger/issue fixes
2 parents 882a450 + a1938a2 commit 47bd3e3

File tree

2 files changed

+43
-38
lines changed

2 files changed

+43
-38
lines changed

src/main/java/Avalara/SDK/ApiClient.java

Lines changed: 43 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -102,17 +102,18 @@ public ApiClient(Configuration config) throws Exception {
102102
init();
103103
initHttpClient();
104104

105+
// TODO: Add back when client creds flow is available through AI.
105106
// Setup authentications (key: authentication name, value: authentication).
106-
if (StringUtils.isNotEmpty(config.getClientId()) && StringUtils.isEmpty(config.getBearerToken())) {
107-
OpenIdHelper.populateConfigWithOpenIdDetails(config);
108-
RetryingOAuth retryingOAuth = new RetryingOAuth(config.getTokenUrl(), config.getClientId(),
109-
config.getClientSecret(), new ClientCredentialsGrant(), null);
110-
authentications.put(
111-
"OAuth",
112-
retryingOAuth
113-
);
114-
initHttpClient(Collections.<Interceptor>singletonList(retryingOAuth));
115-
}
107+
// if (StringUtils.isNotEmpty(config.getClientId()) && StringUtils.isEmpty(config.getBearerToken())) {
108+
// OpenIdHelper.populateConfigWithOpenIdDetails(config);
109+
// RetryingOAuth retryingOAuth = new RetryingOAuth(config.getTokenUrl(), config.getClientId(),
110+
// config.getClientSecret(), new ClientCredentialsGrant(), null);
111+
// authentications.put(
112+
// "OAuth",
113+
// retryingOAuth
114+
// );
115+
// initHttpClient(Collections.<Interceptor>singletonList(retryingOAuth));
116+
// }
116117

117118
// Set Authentication type based on Configuration passed into the ApiClient
118119
if (config.getUsername() != null && config.getPassword() != null) {
@@ -597,6 +598,12 @@ public ApiClient setWriteTimeout(int writeTimeout) {
597598
}
598599

599600

601+
/**
602+
* Format the given parameter object into string.
603+
*
604+
* @param param Parameter
605+
* @return String representation of the parameter
606+
*/
600607
/**
601608
* Format the given parameter object into string.
602609
*
@@ -606,22 +613,36 @@ public ApiClient setWriteTimeout(int writeTimeout) {
606613
public String parameterToString(Object param) {
607614
if (param == null) {
608615
return "";
609-
} else if (param instanceof Date || param instanceof OffsetDateTime || param instanceof LocalDate) {
610-
//Serialize to json string and remove the " enclosing characters
616+
}
617+
// 1) Primitive wrappers and Strings → plain text
618+
if (param instanceof String) {
619+
return (String) param;
620+
}
621+
if (param instanceof Number || param instanceof Boolean) {
622+
return String.valueOf(param);
623+
}
624+
if (param instanceof OffsetDateTime odt) {
625+
// Convert to LocalDateTime and format as ISO_LOCAL_DATE_TIME
626+
return odt
627+
.toLocalDateTime()
628+
.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME);
629+
}
630+
if (param instanceof Date || param instanceof LocalDate) {
611631
String jsonStr = json.serialize(param);
632+
// e.g. "\"2025-05-06T12:00:00Z\"" → "2025-05-06T12:00:00Z"
612633
return jsonStr.substring(1, jsonStr.length() - 1);
613-
} else if (param instanceof Collection) {
634+
}
635+
if (param instanceof Collection) {
614636
StringBuilder b = new StringBuilder();
615-
for (Object o : (Collection) param) {
616-
if (b.length() > 0) {
637+
for (Object o : (Collection<?>) param) {
638+
if (!b.isEmpty()) {
617639
b.append(",");
618640
}
619-
b.append(String.valueOf(o));
641+
b.append(parameterToString(o));
620642
}
621643
return b.toString();
622-
} else {
623-
return String.valueOf(param);
624644
}
645+
return json.serialize(param);
625646
}
626647

627648
/**
@@ -997,8 +1018,7 @@ public <T> ApiResponse<T> execute(Call call) throws ApiException {
9971018
* @throws Avalara.SDK.ApiException If fail to execute the call
9981019
*/
9991020
public <T> ApiResponse<T> execute(Call call, Type returnType) throws ApiException {
1000-
try {
1001-
Response response = call.execute();
1021+
try (Response response = call.execute()) {
10021022
T data = handleResponse(response, returnType);
10031023
return new ApiResponse<T>(response.code(), response.headers().toMultimap(), data);
10041024
} catch (IOException e) {
@@ -1037,16 +1057,14 @@ public void onFailure(Call call, IOException e) {
10371057
@Override
10381058
public void onResponse(Call call, Response response) throws IOException {
10391059
T result;
1040-
try {
1041-
result = (T) handleResponse(response, returnType);
1060+
try (Response r = response) {
1061+
result = (T) handleResponse(r, returnType);
1062+
callback.onSuccess(result, r.code(), r.headers().toMultimap());
10421063
} catch (ApiException e) {
10431064
callback.onFailure(e, response.code(), response.headers().toMultimap());
1044-
return;
10451065
} catch (Exception e) {
10461066
callback.onFailure(new ApiException(e), response.code(), response.headers().toMultimap());
1047-
return;
10481067
}
1049-
callback.onSuccess(result, response.code(), response.headers().toMultimap());
10501068
}
10511069
});
10521070
}

src/main/java/Avalara/SDK/Configuration.java

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -201,19 +201,6 @@ public void setClientId(String clientId) {
201201
ClientId = clientId;
202202
}
203203

204-
/**
205-
* Gets or sets the ClientSecret Used for OAuth2 Client Credentials flow.
206-
*/
207-
private String ClientSecret;
208-
209-
public String getClientSecret() {
210-
return ClientSecret;
211-
}
212-
213-
public void setClientSecret(String clientSecret) {
214-
ClientSecret = clientSecret;
215-
}
216-
217204
/**
218205
* Gets the Base Path.
219206
*/

0 commit comments

Comments
 (0)