Fix - pathParam conversion from enum to string - #2011
Conversation
There was a problem hiding this comment.
Code Review
This pull request updates the Jersey 3 API template to convert non-string path parameters to strings. The reviewer correctly identified that calling .toString() directly on primitive types will result in compilation errors in Java, and suggested using String.valueOf() as a safer alternative.
| throw new IllegalArgumentException("Please provide the {{{paramName}}} path parameter"); | ||
| } | ||
| pathParams.put("{{baseName}}", {{{paramName}}}); | ||
| pathParams.put("{{baseName}}", {{{paramName}}}{{^isString}}.toString(){{/isString}}); |
There was a problem hiding this comment.
If a path parameter is a primitive type (such as int, long, or boolean), calling .toString() directly on it will cause a compilation error in Java because primitive types do not have methods. Using String.valueOf() is a safer and more robust approach because it handles both primitive types and object types (like enums or custom classes) seamlessly.
pathParams.put("{{baseName}}", {{#isString}}{{{paramName}}}{{/isString}}{{^isString}}String.valueOf({{{paramName}}}){{/isString}});
|
|
ok, the mystery is solved: I was pretty sure that we handled these cases already. However, we were handling query params, not path parameters. I wonder whether affected code shouldn't be a query param instead but that's out of scope (at least for now). Adding this example (of query param) for reference: https://github.com/Adyen/adyen-java-api-library/blob/main/src/main/java/com/adyen/service/balanceplatform/TransferLimitsBalanceAccountLevelApi.java#L334-L344 |



Description
Fix template to convert non-String path parameters (e.g. enums) with .toString(), preventing compile errors like the new CampaignStatusTransition status path param in DonationCampaignsApi.
Error
Git hub pipeline - https://github.com/Adyen/adyen-java-api-library/actions/runs/29820136294/job/88600760813?pr=2004