Fixes incorrect Jackson imports in Java templates used in ApiClient.java when useJakartaEe=true
This PR aims to fix a compiler issue I ran into when generating java code from an API spec.
The generated code imports com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider in ApiClient.java, which is the javax package, while my project uses jakarta and requires com.fasterxml.jackson.jakarta.rs.json.JacksonJsonProvider. Upon searching, this seems to be a long-standing issue in this specific configuration, I was able to find at least one issue directly referencing it: #15875.
Upon digging deeper, it seems the generated ApiClient.java file in my particular configuration (using the apache-httpclient library) doesn't even use the imported class, so in this specialized template it can even be omitted, as is the case in a secondary issue reported as #18289.
The PR does not add any new template parameters, but instead switches over the useJakartaEe parameter already exposed to select the appropriate Jackson package to import. This should fix this problem for all Java templates. In addition, I have removed the unused import for the apache-httpclient specifically, since it is not needed.
Tagging committee members as requested in the checklist: @bbdouglas @sreeshas @jfiala @lukoyanov @cbornet @jeff9finger @karismann @Zomzog @lwlee2608 @martin-mfg
I can currently work around the compile issue in my project through an overwritten template file in my template folder where I've fixed this locally, but this PR should fix it for everyone else running into the same issue.
PR checklist
- [X] Read the contribution guidelines.
- [X] Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
- [X] Run the following to build the project and update samples:
(For Windows users, please run the script in Git BASH) Commit all changed files. This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master. These must match the expectations made by your contribution. You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example./mvnw clean package ./bin/generate-samples.sh ./bin/configs/*.yaml ./bin/utils/export_docs_generators.sh./bin/generate-samples.sh bin/configs/java*. IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed. - [X] File the PR against the correct branch:
master(upcoming 7.1.0 minor release - breaking changes with fallbacks),8.0.x(breaking changes without fallbacks) - [X] If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.
Thanks for the PR but your commit (as shown in the Commits tab) is not linked to your Github account, which means this PR won't count as your contribution in https://github.com/OpenAPITools/openapi-generator/graphs/contributors.
Let me know if you need help fixing it.
Ref: https://github.com/OpenAPITools/openapi-generator/wiki/FAQ#how-can-i-update-commits-that-are-not-linked-to-my-github-account
Thanks for the heads-up @wing328 -- incorrect git config on my part. Should be fixed now 🙂
Let me know if you need anything else to get this merged!
@wing328 sorry for the poke, but is there anything else that needs to be done or can this be merged?
I need this too. Please merge and create a new release when possible.
@JochemKuijpers thanks for the PR. I'll run some tests and try to get it merged before the upcoming v7.6.0 release.
tested locally and the output compiles (except jaxrs-cxf-extended, which has the same issue in the latest master anyway, we will look into it separately)
I think this change might have broken Jakarta EE 8 support. Setting useJakartaEE to true doesn't seem to kreate javax imports anymore.
Hi @AdrianDiemerDev, this change has been merged back in May. If you experience any problems with this change or any current behavior of the project, I'd recommend opening a new issue.
However to quickly comment on your issue: it sounds like you're running into the intended behavior of useJakartaEE. When set to true, a user indicates they're looking to use the jakarta packages, not the javax equivalents. You'll see that's the exact intentional behavior of this setting in the documentation.
If you relied on the previous incorrect behavior of using javax packages while requiring this setting this setting to be true, I recommend updating other dependencies and moving away from javax elsewhere in your program, if possible. Otherwise, try setting useJakartaEE to false.
But the Jakarta/Javax transition has been a mess, so I understand your frustration.
To avoid turning this merged PR into a troubleshooting thread, please open a new issue here if you continue to have problems with this change. Feel free to mention me there and I'll see if I can help out.
Hi, thanks for the quick reply.
Yes, I'm aware of the functionality of that switch as well as the trouble with the package renaming.
However, it seems that on my side, setting useJakartaEe to false doesn't have the indended effect anymore when using the generator in version 7.6.0 or newer. I still get jakarta packages. That's not the case when using version 7.5.0 with the exact same configuration. However, I currently don't have the time to investigate this in more detail. Therefore, I'm using version 7.5 for now.
If I find the time to investigate more, I'll create a new issue with further details.
Ah, now I get your confusion... I mixed up true and false in my first comment. I'm sorry!