Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #3098
Closed
Open
Issue created Jun 05, 2019 by Administrator@rootContributor

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

Created by: feliksik

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)
Assignee
Assign to
Time tracking