forked from loafle/openapi-generator-original
[Kotlin] Fix (de)serialization of enum classes (#7917)
While inner enum classes from dataClass.mustache work fine, standalone enum classes lack `@JsonProperty` annotations so that Jackson uses names instead of values.
This commit is contained in:
committed by
GitHub
parent
af992e4b29
commit
4a63aae746
@@ -540,8 +540,10 @@ public class KotlinSpringServerCodegen extends AbstractKotlinCodegen
|
||||
.filter(cm -> Boolean.TRUE.equals(cm.isEnum) && cm.allowableValues != null)
|
||||
.forEach(cm -> {
|
||||
cm.imports.add(importMapping.get("JsonValue"));
|
||||
cm.imports.add(importMapping.get("JsonProperty"));
|
||||
Map<String, String> item = new HashMap<>();
|
||||
item.put("import", importMapping.get("JsonValue"));
|
||||
item.put("import", importMapping.get("JsonProperty"));
|
||||
imports.add(item);
|
||||
});
|
||||
|
||||
|
||||
@@ -4,6 +4,6 @@
|
||||
*/
|
||||
enum class {{classname}}(val value: {{dataType}}) {
|
||||
{{#allowableValues}}{{#enumVars}}
|
||||
{{&name}}({{{value}}}){{^-last}},{{/-last}}{{#-last}};{{/-last}}
|
||||
@JsonProperty({{{value}}}) {{&name}}({{{value}}}){{^-last}},{{/-last}}{{#-last}};{{/-last}}
|
||||
{{/enumVars}}{{/allowableValues}}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user