Skip to content

JAXB2 EnumValue Plugin

Laurent Schoelens edited this page Aug 25, 2023 · 1 revision

JAXB2 EnumValue plugin makes enums implement the EnumValue<T> interface. This allows generic access to the original enum values.

@XmlType(name = "issueJIIB38Type")
@XmlEnum
public enum IssueJIIB38Type
    implements EnumValue<String>
{

    @XmlEnumValue("a")
    A("a"),
    @XmlEnumValue("b")
    B("b"),
    @XmlEnumValue("c")
    C("c"),
    @XmlEnumValue("d")
    D("d");
    private final String value;

    IssueJIIB38Type(String v) {
        value = v;
    }

    public String value() {
        return value;
    }

    public static IssueJIIB38Type fromValue(String v) {
        for (IssueJIIB38Type c: IssueJIIB38Type.values()) {
            if (c.value.equals(v)) {
                return c;
            }
        }
        throw new IllegalArgumentException(v);
    }

    public String enumValue() {
        return this.value();
    }
}

Usage

  • Add JAXB2 Basics to your build.
  • Use the -XenumValue argument to activate the plugin.
Clone this wiki locally