Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

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

m
m (Replacing page with 'Please see http://www.eclipse.org/eclipselink/documentation/2.4/moxy/simple_values004.htm')
 
(33 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{EclipseLink_UserGuide
+
Please see http://www.eclipse.org/eclipselink/documentation/2.4/moxy/simple_values004.htm
|info=y
+
|toc=y
+
|eclipselink=y
+
|eclipselinktype=moxy
+
|api=y
+
|apis= * [http://www.eclipse.org/eclipselink/api/latest/index.html?javax/xml/bind/annotation/XmlAttribute.html XmlAttribute]
+
* [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/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]
+
}}
+
 
+
=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:
+
 
+
<source lang="java">
+
    @XmlEnum(String.class)
+
    public enum Card { CLUBS, DIAMONDS, HEARTS, SPADES }
+
</source>
+
 
+
will generate the following XML schema:
+
 
+
<source lang="xml">
+
    <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>
+
</source>
+
 
+
==Mappin enum constant name(value)==
+
This code:
+
 
+
<source lang="java">
+
    @XmlType
+
    @XmlEnum(Integer.class)
+
    public enum Coin {
+
        @XmlEnumValue("1") PENNY(1),
+
        @XmlEnumValue("5") NICKEL(5),
+
        @XmlEnumValue("10") DIME(10),
+
        @XmlEnumValue("25") QUARTER(25) }
+
</source>
+
 
+
will generate the following XML schema:
+
 
+
<source lang="xml">
+
    <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>
+
</source>
+
 
+
{{EclipseLink_MOXy
+
|previous= [[EclipseLink/UserGuide/MOXy/Simple_Values/Collections/XMLDirectCollectionMapping|XMLDirectCollectionMapping]]
+
|next=    [[EclipseLink/UserGuide/MOXy/Simple_Values/Special_Schema_Types|Special Schema Types]]
+
|up=      [[EclipseLink/UserGuide/MOXy/Simple_Values|Simple Values]]
+
|version=2.2.0 Draft
+
}}
+

Latest revision as of 10:18, 8 November 2012

Please see http://www.eclipse.org/eclipselink/documentation/2.4/moxy/simple_values004.htm

Back to the top