【问题标题】:Can I configure XJC bindings to generate collections as Set instead of List我可以配置 XJC 绑定以将集合生成为 Set 而不是 List
【发布时间】:2010-10-27 04:48:04
【问题描述】:

给定这样的架构:

<xs:element name="Group" type="GroupType"/>

<xs:complexType name="GroupType">
    <xs:sequence>
        <xs:element type="OptionsType" name="Options" maxOccurs="1" minOccurs="1"/>
        <xs:element type="PageContainerType" name="PageContainer" maxOccurs="unbounded" minOccurs="0"/>
    </xs:sequence>
</xs:complexType>

<xs:complexType name="PageContainerType">
    <xs:sequence>
      ...
    </xs:sequence>
</xs:complexType>

XJC 将生成类似以下的 Java:

public class GroupType {
  @XmlElement(name = "Options", required = true)
  protected OptionsType options;
  @XmlElement(name = "PageContainer")
  protected List<PageContainerType> pageContainer;
  ...
}

我想为 PageContainer 元素强制使用唯一的集合。这是一个逆向工程项目,所以我不太关心确保架构明确执行它。

是否可以通过在架构或 XJC 绑定中指定某些内容来将 PageContainer 元素生成为 Set&lt;PageContainerType&gt;

【问题讨论】:

    标签: java xsd jaxb xjc


    【解决方案1】:

    JAXB 运行时(至少 MetroMOXy)可以处理 java.util.Set 类型的属性。示例见:

    Metro 和 MOXy JAXB 实现都使用相同的 XJC 工具将 XML 模式编译成 Java 类。您可能希望将您的问题发布到以下论坛:

    您也可以通过编写 XJC 插件来达到预期的效果:

    【讨论】:

      猜你喜欢
      • 2012-11-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-20
      • 2014-02-23
      • 2010-10-05
      • 2011-11-08
      • 2015-10-08
      相关资源
      最近更新 更多