swagger-core
swagger-core copied to clipboard
Jackson enum value is not used if @JsonValue is on an enum field or nonpublic method
When Jackson's @JsonValue is used on a public enum method, the Swagger enum list properly uses this value (thanks to #3553). However, when it is used on an enum field instead, or on a non-public enum method, the Swagger enum list does not. This causes a discrepancy between what the REST API actually accepts (as defined by Jackson) and what the Swagger definition states it does.
A real quick way to verify this is to update the JacksonValueEnum in the swagger-core test. The EnumPropertyTest.testExtractJacksonEnumFields test will then fail.
public enum JacksonValueEnum {
FIRST("one"),
SECOND("two"),
THIRD("three");
@JsonValue
private final String value;
JacksonValueEnum(String value) {
this.value = value;
}
}
OR
public enum JacksonValueEnum {
FIRST("one"),
SECOND("two"),
THIRD("three");
private final String value;
JacksonValueEnum(String value) {
this.value = value;
}
@JsonValue
private String getValue() {
return value;
}
}
And also @JsonValue not used when on interface method declaration.
public interface ErrorCode {
@JsonValue
String code();
}
public enum Code implements ErrorCode {
SOME_ERROR_CODE("actual_error_code");
private final String code;
Code(String code) {
this.code = code;
}
@Override
public String code() {
return code;
}
}
Had the same issue. Making the @JsonValue field / method public resolved the issue for me.