Skip to content

Conversation

@altro3
Copy link
Collaborator

@altro3 altro3 commented May 24, 2022

Fixed #471

Comment on lines +1373 to +1387
private List<String> getEnumValues(EnumElement type) {
List<String> enumValues = new ArrayList<>();
javax.lang.model.element.Element nativeType = (javax.lang.model.element.Element) type.getNativeType();
for (javax.lang.model.element.Element element : nativeType.getEnclosedElements()) {
if (element.getKind() == ElementKind.ENUM_CONSTANT) {
JsonProperty jsonproperty = element.getAnnotation(JsonProperty.class);
if (jsonproperty != null && StringUtils.hasText(jsonproperty.value())) {
enumValues.add(jsonproperty.value());
} else {
enumValues.add(element.getSimpleName().toString());
}
}
}
return enumValues;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change will only work on Java, we prefer to not have direct dependencies on the javax.lang.model api. Can you alter this to use EnumElement and the values() method is already offers. This possibly will require a change in core.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@graemerocher Hmm... if this method cannot be used - then yes, you will have to modify the kernel. Because now it is possible to get only a list of values, without annotations (Ivan described the problem in the issue). In general, need to add a method to EnumElement that will return a list of values and their annotations

…port for different enum types and default value.

Fixed #471
@altro3
Copy link
Collaborator Author

altro3 commented Aug 7, 2022

Fixed here: #791

@altro3 altro3 closed this Aug 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

JsonProperty not getting picked up by yaml generation for Enum

2 participants