0

I have an XSD and want to mark some properties as XmlTransient, so that the properties will be generated in Java by XJC and ignored by marshalling and unmarshalling by JAXB.

I can modify the XSD and dont know what I should put into xs:annotation tag to customize JAXB binding.

Here is my XSD so far

<?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>
Martin Dames
  • 264
  • 3
  • 13
  • 2
    The schema represents the structure of the instance, so if it's in the schema, it will be in the instance. If you don't want data represented in XML, just remove it from the XSD. You can subclass the generated class and add new properties tagged as @XmlTransient which will not be persisted in XML. – helderdarocha Feb 11 '14 at 19:48

1 Answers1

0

Try the Annotate plugin for this. (Diclaimer: I'm the author.) There's an example for @XmlRootElement, @XmlTransient would be analogous.

<annox:annotate target="class">
    <annox:annotate annox:class="javax.xml.bind.annotation.XmlRootElement"
       namespace="someNamespace"/>
</annox:annotate>
lexicore
  • 42,748
  • 17
  • 132
  • 221
  • I am trying to use the same idea to mark a field transient.But does not seem to work. – Mandar K Sep 26 '15 at 22:38
  • 1
    @MandarKulkarni Unfortunatelly, this is the type of the "does not work" comment noone can do anything with. Ask another question, describe your problem in detail, show what you've tried so far, then maybe you'll get help. As for now the answer to "does not seem to work" is that maybe you're doing something wrong. – lexicore Sep 29 '15 at 07:06
  • Using `@XmlTransient` it appears to be set on the getter rather than the field. Any idea why? I can't change the `XmlAccessorType`, because running xjc with `-Xpropertyaccessors` gives runtime errors, because our xsd is not very consistent, but it's not up to me to change it. – html_programmer Jul 15 '22 at 21:37
  • Attached link is out dated and redirect to spam sites. Please update it if you moved the plugin to different site. – misco Aug 04 '23 at 08:46