Jump to: navigation, search

Difference between revisions of "EclipseLink/UserGuide/MOXy/Simple Values/Enums"

m
m
Line 5: Line 5:
 
|eclipselinktype=moxy
 
|eclipselinktype=moxy
 
|api=y
 
|api=y
|apis= * [http://www.eclipse.org/eclipselink/api/latest/index.html?javax/xml/bind/annotation/XmlAttribute.html XmlAttribute]
+
|apis= * [http://www.eclipse.org/eclipselink/api/latest/index.html?javax/xml/bind/annotation/XmlEnumValue.html XmlEnumValue]
* [http://www.eclipse.org/eclipselink/api/latest/index.html?javax/xml/bind/annotation/XmlElement.html XmlElement]
+
* [http://www.eclipse.org/eclipselink/api/latest/index.html?javax/xml/bind/annotation/XmlEnum.html XmlEnum]
* [http://www.eclipse.org/eclipselink/api/latest/index.html?javax/xml/bind/annotation/XmlElementWrapper.html XmlElementWrapper]
+
* [http://www.eclipse.org/eclipselink/api/latest/index.html?javax/xml/bind/annotation/XmlValue.html XmlValue]
+
* [http://www.eclipse.org/eclipselink/api/latest/index.html?javax/xml/bind/annotation/XmlList.html XmlList]
+
 
}}
 
}}
  
Line 37: Line 34:
 
</source>  
 
</source>  
  
==Mappin enum constant name(value)==
+
==Mapping enum constant name(value)==
 
This code:
 
This code:
  

Revision as of 11:10, 28 December 2010

EclipseLink moxy

link="http://wiki.eclipse.org/EclipseLink"
EclipseLink
Website
Download
Community
Mailing ListForumsIRC
Bugzilla
Open
Help Wanted
Bug Day
Contribute
Browse Source

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>

Eclipselink-logo.gif
Version: 2.2.0 Draft
Other versions...