简体   繁体   中英

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?

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM