微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

JAXB:生成的Java类与架构定义不匹配

如何解决JAXB:生成的Java类与架构定义不匹配

我正在使用xjc从XSD架构生成java类。我的问题是关于以下XSD代码段的:

<xsd:complexType name="JurisdictionCountry_BvType">
   <xsd:sequence>
      <xsd:element name="id" type="JurisdictionCountry_ENUM_List" minOccurs="1"/>
      <xsd:element name="code" type="JurisdictionCountry_CODE_List" minOccurs="0"/>
      <xsd:element name="value" type="JurisdictionCountry_VALUE_List" minOccurs="0"/>
   </xsd:sequence>
<xsd:complexType>

 <xsd:simpleType name="JurisdictionCountry_ENUM_List">
     <xsd:restriction base="xsd:long">
        <xsd:enumeration value="0"/>
        .....
     </xsd:restriction>
 </xsd:simpleType>

 <xsd:simpleType name="JurisdictionCountry_CODE_List">
    <xsd:restriction base="xsd:string">
       <xsd:enumeration value="0"/>
       ....
    </xsd:restriction>
 </xsd:simpleType>

 <xsd:simpleType name="JurisdictionCountry_VALUE_List">
    <xsd:restriction base="xsd:string">
       <xsd:enumeration value="-Select-"/>  
       .....
    </xsd:restriction>
 </xsd:simpleType>

为JurisdictionCountry_BvType生成java类如下:

    @XmlAccessorType(XmlAccesstype.FIELD)
    @XmlType(name = "JurisdictionCountry_BvType",propOrder = {
       "id","code","value"
   })

   public class JurisdictionCountryBvType {
      protected long id;
      protected String code;
      @XmlSchemaType(name = "string")
      protected JurisdictionCountryVALUEList value;
   }

我遇到两个问题:

  1. 未为JurisdictionCountry_ENUM_List和JurisdictionCountry_CODE_List生成java类
  2. “ id”和“ code”变量类型错误

具有类似设置(id和代码变量)的其他元素也会发生相同的情况。我不确定这是否是架构本身的问题?或者是其他东西。该架构由主架构中包含的多个架构文件组成。我以为可能是xsd:restriction,但是JurisdictionCountry_VALUE_List类型具有并且已正确生成。任何帮助/指针将不胜感激。

谢谢。

编辑:我在ext_bindings.jxb中添加了以下内容 mapSimpleTypeDef =“ true” />

这导致生成了JurisdictionCountry_ENUM_List和JurisdictionCountry_CODE_List的java类,但是它们没有来自xsd:enumeration元素的任何值。

@XmlAccessorType(XmlAccesstype.PROPERTY)
@XmlType(name = "JurisdictionState_ENUM_List",propOrder = {
    "value"
})
public class JurisdictionStateENUMList {

    @XmlValue
    protected long value;

    public long getValue() {
        return value;
    }

    public void setValue(long value) {
        this.value = value;
    }
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。