Skip to content

JAXB2 EnumValue Plugin

highsource edited this page Oct 23, 2014 · 3 revisions

JAXB2 EnumValue Plugin

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

Activation