@@ -102,17 +102,18 @@ public ApiClient(Configuration config) throws Exception {
102
102
init ();
103
103
initHttpClient ();
104
104
105
+ // TODO: Add back when client creds flow is available through AI.
105
106
// 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
+ // }
116
117
117
118
// Set Authentication type based on Configuration passed into the ApiClient
118
119
if (config .getUsername () != null && config .getPassword () != null ) {
@@ -597,6 +598,12 @@ public ApiClient setWriteTimeout(int writeTimeout) {
597
598
}
598
599
599
600
601
+ /**
602
+ * Format the given parameter object into string.
603
+ *
604
+ * @param param Parameter
605
+ * @return String representation of the parameter
606
+ */
600
607
/**
601
608
* Format the given parameter object into string.
602
609
*
@@ -606,22 +613,36 @@ public ApiClient setWriteTimeout(int writeTimeout) {
606
613
public String parameterToString (Object param ) {
607
614
if (param == null ) {
608
615
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 ) {
611
631
String jsonStr = json .serialize (param );
632
+ // e.g. "\"2025-05-06T12:00:00Z\"" → "2025-05-06T12:00:00Z"
612
633
return jsonStr .substring (1 , jsonStr .length () - 1 );
613
- } else if (param instanceof Collection ) {
634
+ }
635
+ if (param instanceof Collection ) {
614
636
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 () ) {
617
639
b .append ("," );
618
640
}
619
- b .append (String . valueOf (o ));
641
+ b .append (parameterToString (o ));
620
642
}
621
643
return b .toString ();
622
- } else {
623
- return String .valueOf (param );
624
644
}
645
+ return json .serialize (param );
625
646
}
626
647
627
648
/**
@@ -997,8 +1018,7 @@ public <T> ApiResponse<T> execute(Call call) throws ApiException {
997
1018
* @throws Avalara.SDK.ApiException If fail to execute the call
998
1019
*/
999
1020
public <T > ApiResponse <T > execute (Call call , Type returnType ) throws ApiException {
1000
- try {
1001
- Response response = call .execute ();
1021
+ try (Response response = call .execute ()) {
1002
1022
T data = handleResponse (response , returnType );
1003
1023
return new ApiResponse <T >(response .code (), response .headers ().toMultimap (), data );
1004
1024
} catch (IOException e ) {
@@ -1037,16 +1057,14 @@ public void onFailure(Call call, IOException e) {
1037
1057
@ Override
1038
1058
public void onResponse (Call call , Response response ) throws IOException {
1039
1059
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 ());
1042
1063
} catch (ApiException e ) {
1043
1064
callback .onFailure (e , response .code (), response .headers ().toMultimap ());
1044
- return ;
1045
1065
} catch (Exception e ) {
1046
1066
callback .onFailure (new ApiException (e ), response .code (), response .headers ().toMultimap ());
1047
- return ;
1048
1067
}
1049
- callback .onSuccess (result , response .code (), response .headers ().toMultimap ());
1050
1068
}
1051
1069
});
1052
1070
}
0 commit comments