So I know how to create an enum type but when I set an element type to it the element field will just be of type string and not of type enum. How do I create an enum in my schem
You could form your XML schema as follows:
Will cause the following Enum to be generated:
package com.example;
import javax.xml.bind.annotation.*;
@XmlType(name = "myEnum")
@XmlEnum
public enum MyEnum {
MY_ENUM_1,
MY_ENUM_2;
public String value() {
return name();
}
public static MyEnum fromValue(String v) {
return valueOf(v);
}
}
And the following class that leverages that Enum:
package com.example;
import javax.xml.bind.annotation.*;
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"local",
"ref"
})
@XmlRootElement(name = "root")
public class Root {
@XmlElement(required = true)
protected MyEnum local;
@XmlElement(required = true)
protected MyEnum ref;
public MyEnum getLocal() {
return local;
}
public void setLocal(MyEnum value) {
this.local = value;
}
public MyEnum getRef() {
return ref;
}
public void setRef(MyEnum value) {
this.ref = value;
}
}
For More Information