Skip to content

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

Open
@feliksik

Description

@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:

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions