Skip to content

Commit

Permalink
added jackson annotations on oneof generated interface for deserializ…
Browse files Browse the repository at this point in the history
…ation
  • Loading branch information
HugoMario committed Dec 19, 2021
1 parent 137b149 commit e3fbdfd
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,17 @@ protected void addInterfaces(List<Schema> schemas, CodegenModel codegenModel, Ma
continue;
}
final String schemaName = ref.substring(ref.lastIndexOf("/") + 1);
this.addInterfaceModel(allModels.get(codegenConfig.toModelName(schemaName)), codegenModel);

final CodegenModel model = allModels.get(codegenConfig.toModelName(schemaName));
this.addInterfaceModel(model, codegenModel);

boolean subTypeAdded = false;
if (codegenModel.getSubTypes() != null) {
subTypeAdded = codegenModel.getSubTypes().stream().anyMatch(existingSubType -> existingSubType.classname.equalsIgnoreCase(model.classname));
}
if (!subTypeAdded) {
codegenModel.addSubType(model);
}
}
}

Expand Down
15 changes: 15 additions & 0 deletions src/main/resources/handlebars/Java/interface.mustache
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
{{#jackson}}
import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
{{/jackson}}
/**
* {{#description}}{{.}}{{/description}}{{^description}}{{classname}}{{/description}}
*/
{{#jackson}}
@JsonTypeInfo(
use = JsonTypeInfo.Id.NAME,
include = JsonTypeInfo.As.PROPERTY,
property = "type")
@JsonSubTypes({
{{#subTypes}}
@JsonSubTypes.Type(value = {{classname}}.class, name = "{{classname}}"){{^@last}},{{/@last}}
{{/subTypes}}
})
{{/jackson}}
public interface {{{classname}}} {
}

0 comments on commit e3fbdfd

Please sign in to comment.