Skip to content

Commit

Permalink
[Kotlin] Fix (de)serialization of enum classes (#7917)
Browse files Browse the repository at this point in the history
While inner enum classes from dataClass.mustache work fine, standalone enum classes lack `@JsonProperty` annotations so that Jackson uses names instead of values.
  • Loading branch information
cschramm committed Apr 16, 2021
1 parent af992e4 commit 4a63aae
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -540,8 +540,10 @@ public Map<String, Object> postProcessModelsEnum(Map<String, Object> objs) {
.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);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
}

0 comments on commit 4a63aae

Please sign in to comment.