Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JAXB Documentation Annotation

Tags:

java

jaxb

xsd

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>
like image 265
emeraldjava Avatar asked Jan 22 '09 17:01

emeraldjava


2 Answers

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

like image 96
boutta Avatar answered Oct 05 '22 08:10

boutta


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>
like image 32
dlinsin Avatar answered Oct 05 '22 10:10

dlinsin