swagger-codegen icon indicating copy to clipboard operation
swagger-codegen copied to clipboard

[Java/GSON] Fix error with enums of integer type

Open craffael opened this issue 8 years ago • 2 comments

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.sh and ./bin/security/{LANG}-petstore.sh if 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.0 branch 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().

craffael avatar Nov 26 '17 11:11 craffael

@bbdouglas @sreeshas @jfiala @lukoyanov What do you think?

craffael avatar Dec 07 '17 09:12 craffael

Any Chance this will be part of an upcoming release soon?

svhi avatar Mar 26 '19 09:03 svhi