-
Couldn't load subscription status.
- Fork 2.2k
Support for overriding enum values with @JsonProperty or @JsonValue #3553
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Need this! Please merge! |
|
@frantuma Anything I can help you with for reviewing this PR? |
| final boolean useToString = _mapper.isEnabled(SerializationFeature.WRITE_ENUMS_USING_TO_STRING); | ||
|
|
||
|
|
||
| Optional<Method> jsonValueMethod = Arrays.stream(propClass.getMethods()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@frantuma @joschi
It might be a better idea to utilize findJsonValueAccessor from BeanDescriptor since it also supports JsonValue annotations specified in interfaces.
The current implementation fails on
public interface ApiEnum {
@JsonValue
String jsonValue();
}
public enum ResponseType implements ApiEnum {
Http("http"),
Websocket("websocket");
private String description;
ResponseType(String description) {
this.description = description;
}
@Override
public String jsonValue() {
return description;
}
}
while we're able to retrieve the actual jsonValueAccessor via
var typeFactory = TypeFactory.defaultInstance();
var type = typeFactory.constructFromCanonical(ResponseType.class.getCanonicalName());
var beanDesc = Json.mapper().getSerializationConfig().introspect(type);
var accessor = beanDesc.findJsonValueAccessor();
This PR adds support for overriding enum values with the Jackson-specific annotations
@JsonPropertyor@JsonValue.Those annotations allow customizing how enum values are serialized and deserialized by Jackson and this PR consolidates the generated OpenAPI specification with this customization.
Java example enums (both serializing and deserializing identically when using Jackson):
Results in the generated OpenAPI specification:
Closes #3552