如何使用XJC为属性添加@XmlTransient注释

时间:2014-02-11 19:26:13

标签: java jaxb xsd hyperjaxb xmltransient

我有一个XSD,并希望将某些属性标记为XmlTransient,以便XJC在Java中生成属性,并通过JAXB的编组和解组忽略这些属性。

我可以修改XSD,不知道我应该把什么放到xs:annotation标签中来自定义JAXB绑定。

到目前为止,这是我的XSD

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:hj="http://hyperjaxb3.jvnet.org/ejb/schemas/customizations" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:orm="http://java.sun.com/xml/ns/persistence/orm" jaxb:extensionBindingPrefixes="hj orm">
  <xs:complexType name="tripRegisterType">
    <xs:annotation>
      <xs:appinfo>
        <hj:entity>
          <orm:table name="simplemaketripprocess_tripregistertype" />
        </hj:entity>
        <hj:generated-id name="tripregistertypeid" />
      </xs:appinfo>
    </xs:annotation>
    <xs:sequence>
      <xs:element name="startDate" type="xs:date">
        <xs:annotation>
          <xs:appinfo>
            <hj:basic>
              <orm:column name="startDate" column-definition="timestamp" />
            </hj:basic>
          </xs:appinfo>
        </xs:annotation>
      </xs:element>
      <xs:element name="endDate" type="xs:date">
        <xs:annotation>
          <xs:appinfo>
            <hj:basic>
              <orm:column name="endDate" column-definition="timestamp" />
            </hj:basic>
          </xs:appinfo>
        </xs:annotation>
      </xs:element>
      <xs:element name="want_flight" type="xs:boolean" />
      <xs:element name="want_hotel" type="xs:boolean" />
      <xs:element name="want_car" type="xs:boolean" />
      <xs:element name="payAccNumber" type="xs:string" />

      <!-- THE NEXT COLOUMS I'D LIKE TO BE XML TRANSIENT-->

      <xs:element name="companyid" type="xs:long" />
      <xs:element name="groupid" type="xs:long" />
      <xs:element name="userid" type="xs:long" />
      <xs:element name="username" type="xs:string" />
      <xs:element name="createDate" type="xs:date">
        <xs:annotation>
          <xs:appinfo>
            <hj:basic>
              <orm:column name="createDate" column-definition="timestamp" />
            </hj:basic>
          </xs:appinfo>
        </xs:annotation>
      </xs:element>
      <xs:element name="modifiedDate" type="xs:date">
        <xs:annotation>
          <xs:appinfo>
            <hj:basic>
              <orm:column name="modifiedDate" column-definition="timestamp" />
            </hj:basic>
          </xs:appinfo>
        </xs:annotation>
      </xs:element>
    </xs:sequence>
  </xs:complexType>
</xs:schema>

1 个答案:

答案 0 :(得分:1)

为此尝试Annotate插件。 (Diclaimer:我是作者。) @XmlRootElement有一个示例,@XmlTransient类似。

<annox:annotate target="class">
    <annox:annotate annox:class="javax.xml.bind.annotation.XmlRootElement"
       namespace="someNamespace"/>
</annox:annotate>