Open
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 [REQ] Java: Use MACRO_CASE for generated enums #2867 ) - generate an ObjectMapper along with the DTOs, that respects the assumptions made by the generator (would also save the DateTime issues)