11
votes

I have the following java class with the JAXB @XMLRootElement annotation

@XmlRootElement(name="ClientData")
public class ClientData {

/**
 * The first address field of the person
 */
private String address1 = null;
}

which produces this xml fragment when i generate the xsd schema

<xs:complexType name="clientData">
  <xs:sequence>
   <xs:element minOccurs="0" name="address1" type="xs:string"/>

Is it possible to use a JAXB annotation so that the documentation details on the address1 field will be included as a xs:annotation/xs:documentention element in my final schema?

<xs:complexType name="clientData">
  <xs:sequence>
   <xs:element minOccurs="0" name="address1" type="xs:string">
    <xs:annotation>
      <xs:documentation>The first address field of the person</xs:documentation>
    </xs:annotation>
   </xs:element>
2

2 Answers

4
votes

Simple answer: no it's not possible with builtin JAXB.

2
votes

I don't know if it's possible, since I've never used it. But as far as I can tell the API doesn't support the documentation element. However, you could use the @XMLElement annotation to give your member a more descriptive name.

//Example: Code fragment
public class USPrice {
   @XmlElement(name="itemprice")
   public java.math.BigDecimal price;
}

<!-- Example: Local XML Schema element -->
<xs:complexType name="USPrice"/>
   <xs:sequence>
     <xs:element name="itemprice" type="xs:decimal" minOccurs="0"/>
   </sequence>
</xs:complexType>