OpenAPITools / OpenAPITools/openapi-generator
[BUG][JAVA] enum are generated in UPPER_CASE but this breaks json deserialization
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Description
In the default Java generator, enums specified withCamelCasing (example) in the spec are converted to WITHCAMELCASING in the java code ( example ). This is idiomatic, but breaks json deserialization (jackson 2.9.6).
See https://github.com/feliksik/bug-reports/tree/master/openapi-generator/enum-casing for the exact step to reproduce (run mvn generate-sources) .
Workaround:
The following ObjectMapper will make it work; note that there is also a hack WRITE_DATES_AS_TIMESTAMPS, which relates to another dateTime serialization problem i have had (cannot find the issue now). I do not consider this a proper solution if people have to write this themselves, as it's pretty costly to discover and fix this stuff.
new ObjectMapper()
.registerModule(new JavaTimeModule())
.enable(DeserializationFeature.READ_ENUMS_USING_TO_STRING)
.enable(SerializationFeature.WRITE_ENUMS_USING_TO_STRING)
.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); // this is also painful!
Suggest a fix
Options are:
- generate
theInputAsIs(although this conflicts with https://github.com/OpenAPITools/openapi-generator/issues/2867 ) - generate an ObjectMapper along with the DTOs, that respects the assumptions made by the generator (would also save the DateTime issues)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked enum-casing spec and generated Response.java, then run the documented mvn generate-sources reproduction. Compare the enum values produced by the default Java generator with Jackson 2.9.6 deserialization behavior. Done should mean the agreed enum representation deserializes correctly without requiring each user to provide the workaround ObjectMapper.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100