[Java/GSON] Fix error with enums of integer type
PR checklist
- [x] Read the contribution guidelines.
- [x] Ran the shell script under
./bin/to update Petstore sample so that CIs can verify the change. (For instance, only need to run./bin/{LANG}-petstore.shand./bin/security/{LANG}-petstore.shif updating the {LANG} (e.g. php, ruby, python, etc) code generator or {LANG} client's mustache templates). Windows batch files can be found in.\bin\windows\. - [x] Filed the PR against the correct branch:
3.0.0branch for changes related to OpenAPI spec 3.0. Default:master. - [x] Copied the technical committee to review the pull request if your PR is targeting a particular programming language. @JFCote
Description of the PR
This is the second attempt to fix issue #6806 . The first attempt (PR https://github.com/swagger-api/swagger-codegen/pull/7051) introduced a new variable to CodegenModel.java which was rather ugly. The present fix uses an entirely different approach by rewriting the GSON adapter for enums, i.e. only two mustache templates have to be changed.
I have tested the generated code with enums of type string and integer and it worked in both cases. This solution essentially relies on special behavior of com.google.gson.stream.JsonReader#nextString().
@bbdouglas @sreeshas @jfiala @lukoyanov What do you think?
Any Chance this will be part of an upcoming release soon?