Skip to content

Jackson enum value is not used if @JsonValue is on an enum field or nonpublic method #3998

@mjustin

Description

@mjustin

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;
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions