Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.
Difference between revisions of "EclipseLink/UserGuide/MOXy/Simple Values/Enums"
< EclipseLink | UserGuide | MOXy | Simple Values
m |
m |
||
Line 61: | Line 61: | ||
{{EclipseLink_MOXy | {{EclipseLink_MOXy | ||
− | |previous= [[EclipseLink/UserGuide/MOXy/Simple_Values/Collections/XMLDirectCollectionMapping| | + | |previous= [[EclipseLink/UserGuide/MOXy/Simple_Values/Collections/XMLDirectCollectionMapping|Mapping collections of Simple Values]] |
|next= [[EclipseLink/UserGuide/MOXy/Simple_Values/Special_Schema_Types|Special Schema Types]] | |next= [[EclipseLink/UserGuide/MOXy/Simple_Values/Special_Schema_Types|Special Schema Types]] | ||
|up= [[EclipseLink/UserGuide/MOXy/Simple_Values|Simple Values]] | |up= [[EclipseLink/UserGuide/MOXy/Simple_Values|Simple Values]] | ||
|version=2.2.0 Draft | |version=2.2.0 Draft | ||
}} | }} |
Revision as of 14:21, 6 January 2011
EclipseLink MOXy
EclipseLink | |
Website | |
Download | |
Community | |
Mailing List • Forums • IRC • mattermost | |
Issues | |
Open • Help Wanted • Bug Day | |
Contribute | |
Browse Source |
Key API
Mapping Enums
Use the @XmlEnumValue annotation with XmlEnum to map an enum constant in Enum type to XML representation. The @XmlEnumValue annotation can be used with the enum constant element.
Mapping enum constant name
This code:
@XmlEnum(String.class) public enum Card { CLUBS, DIAMONDS, HEARTS, SPADES }
will generate the following XML schema:
<xs:simpleType name="Card"> <xs:restriction base="xs:string"/> <xs:enumeration value="CLUBS"/> <xs:enumeration value="DIAMONDS"/> <xs:enumeration value="HEARTS"/> <xs:enumeration value="SPADES"/> </xs:simpleType>
Mapping enum constant name(value)
This code:
@XmlType @XmlEnum(Integer.class) public enum Coin { @XmlEnumValue("1") PENNY(1), @XmlEnumValue("5") NICKEL(5), @XmlEnumValue("10") DIME(10), @XmlEnumValue("25") QUARTER(25) }
will generate the following XML schema:
<xs:simpleType name="Coin"> <xs:restriction base="xs:int"> <xs:enumeration value="1"/> <xs:enumeration value="5"/> <xs:enumeration value="10"/> <xs:enumeration value="25"/> </xs:restriction> </xs:simpleType>