我有simpleType Enum,从以下架构生成JAXB类时行为不同:
<xsd:element name="genderCode" type="GenderCodeType" minOccurs="0" />
<xsd:simpleType name="GenderCodeType" >
<xsd:restriction base="xsd:string">
<xsd:enumeration value="F" />
<xsd:enumeration value="M" />
</xsd:restriction>
</xsd:simpleType>
它生成:
@XmlElement
protected String genderCode;
如下所示生成实际枚举类型:
<xsd:element name="genderCode" type="base:Gender" minOccurs="0" />
<xsd:simpleType name="Gender">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="M"/>
<xsd:enumeration value="F"/>
<xsd:enumeration value="U"/>
</xsd:restriction>
</xsd:simpleType>
...
@XmlType(name = "Gender")
@XmlEnum
public enum Gender {
M, F, U;
public String value() {
return name();
}
public static Gender fromValue(String v) {
return valueOf(v);
}
}
...
@XmlElement
protected Gender genderCode;