zoukankan      html  css  js  c++  java
  • JAXB

    The basic annotation for a field that's intended to be an element is XmlElement. It permits you to define the XML element name, the namespace, whether it is optional or nillable, a default value and the Java class. Here are two annotated fields, and below is the corresponding schema snippet.

    @XmlElement(name = "Preamble", required = true)
    protected PreambleType preamble;
    @XmlElement(name = "Workplace", required = true)
    protected List<SysWorkplaceType> workplace;
    <xsd:sequence>
        <xsd:element name="Preamble" type="com:PreambleType"/>
        <xsd:element name="Workplace" type="SysWorkplaceType" minOccurs="1" maxOccurs="unbounded"/>
    </xsd:sequence>

    If a field has some collection type, more than one @XmlElement may have to be associated with this field. This requires that these annotations are assembled in a XmlElements (not the plural "s") annotation that merely acts as a container. In the class definition below, the field entryOrChoiceOrCascade is a collection composed from objects of three different classes.

    @XmlType(name = "MenuType")
    public class MenuType extends ItemType {
    
        @XmlElements({
            @XmlElement(name = "Item",     type = ItemType.class),
            @XmlElement(name = "CheckBox", type = CheckBoxType.class),
            @XmlElement(name = "Menu",     type = MenuType.class)
        })
        protected List entryList;
    }

    As a bonus you may avoid the complicated name for the list element that JAXB concocts from the first three possibles.

  • 相关阅读:
    [华为]字符串反转
    [华为]字符个数统计
    [华为]字符串分隔
    [华为]计算字符个数
    [华为]字符串最后一个单词的长度
    感悟-思考-生活
    [百度校招]打印全排列
    [阿里]逆序打印整数,要求递归实现
    [百度]数组中去掉连续重复的数字,只保留1个
    百度NLP三面
  • 原文地址:https://www.cnblogs.com/huey/p/5512264.html
Copyright © 2011-2022 走看看