tags:

views:

1372

answers:

2

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>
+1  A: 

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>
david
yeah - i was thinking this is an easy workaround, but i can imagine the field name lengths getting longer as more specific fields are added to the class. I wanted to add the business user definitions for the fields as a documentation tag, and leave the java field naming to the developers. thanks.
emeraldjava
+1  A: 

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

boutta