?? jaxb-annotations.xtp
字號:
<document><header> <title>JAXB Annotations for SOA/IoC</title> <version>Resin 3.1</version> <description><p>JAXB annotations customize the serialization of a model bean.</p> </description></header><body><localtoc/><defun title="@XmlAccessorType"><p>@XmlAccessorType sets default field and property serializability.By default, JAXB serializes public fields and properties. By setting@XmlAccessorType, the bean can choose to only allow annotated fieldsto be serialized.</p><p>@XmlAccessorType works with the other annotations and<a href="#@XmlTransient">@XmlTransient</a> to serialize fields and properties.@XmlTransient prevents serialization, overriding the @XmlAccessorType.The presense of any other annotation will force serialization,overriding the @XmlAccessorType.</p><deftable title="@XmlAccessorType values"><tr> <td>NONE</td> <td>Only annotated fields and properites should be serialized></td></tr><tr> <td>FIELD</td> <td>All fields (public or private) should be serialized></td></tr><tr> <td>PROPERTY</td> <td>All properties (public or private) should be serialized></td></tr><tr> <td>PUBLIC_MEMBER</td> <td>Public fields and properties></td></tr></deftable><example title="@XmlAccessorType serializing fields">@XmlAccessorType(XmlAccessType.FIELD)class Bean { private String data;}</example><example title="XML Document"><Bean> <data>Sample Data</data></Bean></example><def title="@XmlAccessorType">@Target(value={PACKAGE,TYPE})public @interface XmlAccessorType { public XmlAccessType value() default XmlAccessType.PUBLIC_MEMBER;}</def><def title="XmlAccessType">public enum XmlAccessType { FIELD, NONE, PROPERTY, PUBLIC_MEMBER;}</def></defun><defun title="@XmlAttribute"><p>@XmlAttribute marks a field or property as serialized to anXML attribute. By default, fields serialize to XML elements.It can also customize the XML attribute name and namespace.</p><p>@XmlAttribute can work with<a href="#@XmlAccessorType">@XmlAccessorType</a> to select which fieldsand properties should be serialized to XML. By default, public fieldsand properties will be serialized. Adding @XmlAttribute to a privatefield will mark that field as serializable.</p><p>@XmlAttribute can also customize the XML attribute name. By default, theXML attribute name is taken from the field name or the property name. The <code>name()</code> value of the @XmlAttribute annotation will overridethe default element name.</p><example title="@XmlAttribute for a private field">@XmlRootElementclass Bean { @XmlAttribute("sample-field") private String _myField;}</example><example title="XML document for the Bean"><Bean sample-field="A sample value"></Bean></example><def title="@XmlAttribute definition">@Target(value={FIELD,METHOD})public @interface XmlAttribute { public String name() default "##default"; public boolean required() default false; public String namespace() default "##default";}</def></defun><defun title="@XmlElement"><p>@XmlElement marks a field or property as serialized to anXML element. It can also customize the XML element name and namespace.</p><p>@XmlElement can work with<a href="#@XmlAccessorType">@XmlAccessorType</a> to select which fieldsand properties should be serialized to XML. By default, public fieldsand properties will be serialized. Adding @XmlElement to a privatefield will mark that field as serializable.</p><p>@XmlElement can also customize the XML element name. By default, theXML element name is taken from the field name or the property name. The <code>name()</code> value of the @XmlElement annotation will overridethe default element name.</p><example title="@XmlElement for a private field">@XmlRootElementclass Bean { @XmlElement("sample-field") private String _myField;}</example><example title="XML document for the Bean"><Bean> <sample-field>A sample value</sample-field></Bean></example><def title="@XmlElement definition">@Target(value={FIELD,METHOD})public @interface XmlElement { public String name() default "##default"; public boolean nillable() default false; public boolean required() default false; public String namespace() default "##default"; public String defaultValue() default "\u0000"; public Class type() DEFAULT.class;}</def></defun><defun title="@XmlElements"><p>@XmlElements allows lists to contain multiple different tags. Itcontains a list of @XmlElement values allowed as values.</p><example title="@XmlElement allowing two tags">class Bean { @XmlElements({ @XmlElement(name="a",type=BeanA.class), @XmlElement(name="b",type=BeanB.class) }) private List<SubBean> data = new List<SubBean>();}class BeanA extends SubBean { @XmlValue private String data;}class BeanB extends SubBean { @XmlValue private String data;}</example><example title="XML document for the example"><Bean> <a>Some BeanA Data</a> <b>Some BeanB Data</b> <a>Another BeanA Data</a></Bean></example><def title="@XmlElements definition">@Target(value={FIELD,METHOD})public @interface XmlElements { public XmlElement[] value();}</def></defun><defun title="@XmlElementWrapper"><p>@XmlElementWrapper adds a wrapper XML tag for list values.By default, JAXB list values are serialized directly without any extratags. @XmlElementWrapper adds a container XML tags.</p><example title="Bean example with @XmlElementWrapper">class Bean { @XmlElementWrapper(name="values") private List<String> data = new ArrayList<String>();}</example><example title="XML document for example"><Bean> <values> <data>Some data</data> <data>Another item</data> <data>Third item</data> </values></Bean></example><def title="@XmlElementWrapper definition">@Target(value={FIELD,METHOD})public @interface XmlElementWrapper { public String name() default "##default"; public String namespace() default "##default"; public boolean nillable() default false;}</def></defun><defun title="@XmlJavaTypeAdapter"><p>@XmlJavaTypeAdapter specifies a Java class which convertshelper values to final values.</p><p>In some cases, the Java model may not directly match the XMLmodel. For example, it's complicated to represent Java maps inXML. The @XmlJavaTypeAdapter provides a standard way of managingcomplex types.</p><example title="Maps in a Bean">class Bean { @XmlJavaTypeAdapter(MyMapAdapter.class) private HashMap<String,String> map;}class MyMapAdapter extends XmlAdapter<Temp,Map<String,String>> { ...}class Temp { @XmlElement private List<Item> entry = new ArrayList<item>();}class Item { @XmlAttribute private String key; @XmlAttribute private String value;}</example><example title="XML Document"><Bean> <entry key="a" value="data-a"/> <entry key="b" value="data-b"/> <entry key="c" value="data-c"/></Bean></example><def title="@XmlJavaTypeAdapter">@Target({PACKAGE, FIELD, METHOD, TYPE, PARAMETER})public @interface XmlJavaTypeAdapter { Class<? extends XmlAdapter> value(); Class type() default DEFAULT.class;}</def></defun><defun title="@XmlRootElement"><p>@XmlRootElement marks a class as a top-level XML node. @XmlRootElementcan also be used with @XmlElementRef to handle some inheritance situations.</p><p>The <code>name()</code> value of @XmlRootElement customizes theXML name used to serialize a top-level element. The default value isthe class name.</p><example title="@XmlRootElement for renaming">@XmlRootElement(name="my-bean")class Bean { public String data;}</example><example title="XML document for the Bean"><my-bean> <data>A sample value</data></my-bean></example><def title="@XmlRootElement definition">@Target(value=TYPE)public @interface XmlRootElement { public String name() default "##default"; public String namespace() default "##default";}</def></defun><defun title="@XmlTransient"><p>@XmlTransient marks a field or property as unserializable. JAXBwill ignore the transient field.</p><def title="@XmlTransient annotation">@Target(value={FIELD,METHOD})public @interface XmlTransient {}</def></defun><defun title="@XmlValue"><p>@XmlValue marks a single field as representing the entire contentof the bean. If a bean has an @XmlValue annotation, no otherproperty or field may be serialized.</p><example title="@XmlValue filling a bean">class Bean { @XmlValue private String data;}</example><example title="XML document for @XmlValue"><Bean>Sample Data</Bean></example><def title="@XmlValue definition">@Target(value={FIELD,METHOD})public @interface XmlValue {}</def></defun></body></document>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -