Skip to content
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

Jackson enum value is not used if @JsonValue is on an interface method #4466

Open
take-a-hike opened this issue Aug 24, 2023 · 0 comments
Open

Comments

@take-a-hike
Copy link

When Jackson's @JsonValue is used on an enum method, the Swagger enum list properly uses this value. However, when it is used on an interface method which is implemented by the enum, 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.

To verify the behavior, update the JacksonValueEnum in the swagger-core test. The EnumPropertyTest.testExtractJacksonEnumFields test will then fail.

Custom enum interface:

public interface CustomEnum {
    @JsonValue
    String getValue();
}

Updated enum to implement the interface:

public enum JacksonValueEnum implements CustomEnum {
    FIRST("one"),
    SECOND("two"),
    THIRD("three"),
    @Hidden HIDDEN("hidden");

    private final String value;

    JacksonValueEnum(String value) {
        this.value = value;
    }
 
    @Override
    public String getValue() {
        return value;
    }
}
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

No branches or pull requests

1 participant