OpenAPITools / OpenAPITools/openapi-generator

[BUG][JAVA] enum are generated in UPPER_CASE but this breaks json deserialization

Open
#3,098 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Client: Java Feature: Enum Issue: Bug
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:

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.