emeraldjava
emeraldjava

Reputation: 11190

Creating a custom JAXB annotation

Do people have any recommendations on how i could write my own custom JAXB annotation handling class to support the generation of xs:annotation/xs:documentation elements in the xsd schema?. I'd like to create a new java annotation "@XmlAnnotation" which would include a "documentation" attribute. I'd then make these classes available to the JAXB schema generator via the classpath. The schema generator would then take this sample java code

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

/**
 * The first address field of the person
 */
@XmlAnnotation(documentation="The first address field of the client")
private String address1 = null;
}

and create this xsd 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 client</xs:documentation>
</xs:annotation>

Would it be easier to extend from the existing @XmlElement annotation class, and just add support of an extra documentation attribute?

Upvotes: 2

Views: 2151

Answers (2)

leet3lite
leet3lite

Reputation:

That would only allow the construct for the root element. It is valid in just about ALL the xs namespace elements.

I don't understand why it wasn't supported as standard.

Upvotes: 0

Pierre
Pierre

Reputation: 35226

This XmlRootElement is almost empty ( http://docjar.org/src/api/javax/xml/bind/annotation/XmlRootElement.java, there is not 'active' code inside

The main modification would be to change the code using this annotation and generating the xsd file.

Upvotes: 1

Related Questions