Skip to content

@JsonAlias ignored in enum if @JsonValue is present #6210

Description

@bugada

Search before asking

  • I searched in the issues and found nothing similar.

Describe the bug

@JsonAlias is ignored when using @jsonvalue, while it works if @jsonvalue is not present.
This is against the documentation.

Version Information

3.1.5

Reproduction

Using this code passing the value "V" in a json raises this exception

tools.jackson.databind.exc.InvalidFormatException: Cannot deserialize value of type mypackage.enumeration.Versus from String "V": not one of the values accepted for Enum class: [B, S]

package mypackage.enumeration.Versus;

import com.fasterxml.jackson.annotation.JsonAlias;
import com.fasterxml.jackson.annotation.JsonValue;

public enum Versus {

  @JsonAlias({ "A", "B" }) BUY("B"),
  @JsonAlias({ "V", "S" }) SELL("S");

  private String value;

  Versus(String value) {
    this.value = value;
  }

  @JsonValue
  public String getValue() {
    return value;
  }

}

Expected behavior

Passing "V" or "S" it must return "S".

Additional context

After some researches it seems that EnumResolver.constructUsingMethod() (called only if @jsonvalue is present) doesn't fire findEnumAliases().

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    to-evaluateIssue that has been received but not yet evaluated

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions