Note that there are some explanatory texts on larger screens.

plurals
  1. POInsert custom annotation in java 'field' using annotate plugin + JAXB (upon xsd -> java)
    text
    copied!<p>Use case:</p> <p>Wanna insert custom annotation to fields in java class generated by JAXB</p> <p>Problem:</p> <p>Using Annotate plugin + JAXB [1], am able to successfully insert custom annotations but they are getting inserted at getter method rather than field. Morphia (mongo DB) annotations (that i actually want to insert) however can annotate only java fields [2].</p> <p>My test xsd:</p> <pre><code>&lt;xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" jaxb:version="2.1" xmlns:annox="http://annox.dev.java.net" jaxb:extensionBindingPrefixes="annox"&gt; &lt;xsd:element name="hoo" type="External" /&gt; &lt;xsd:complexType name="External"&gt; &lt;xsd:sequence&gt; &lt;xsd:element name="bar" type="xsd:string" /&gt; &lt;xsd:element name="hoobar" type="xsd:string" /&gt; &lt;/xsd:sequence&gt; &lt;/xsd:complexType&gt; &lt;/xsd:schema&gt; </code></pre> <p>My test binding xjb:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8" standalone="yes"?&gt; &lt;jaxb:bindings version="2.1" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:annox="http://annox.dev.java.net" jaxb:extensionBindingPrefixes="annox"&gt; &lt;jaxb:bindings schemaLocation="external.xsd" node="/xs:schema"&gt; &lt;jaxb:bindings node="xs:complexType[@name='External']/xs:sequence/xs:element[@name='bar']"&gt; &lt;annox:annotate&gt; &lt;annox:annotate annox:class="java.lang.SuppressWarnings" impl="com.acme.foo.MyFieldBridge"&gt; &lt;/annox:annotate&gt; &lt;/annox:annotate&gt; &lt;/jaxb:bindings&gt; </code></pre> <p></p> <p></p> <p>My generated java snippet:</p> <pre><code> @XmlElement(required = true) protected String bar; @XmlElement(required = true) protected String hoobar; /** * Gets the value of the bar property. * * @return * possible object is * {@link String } * */ @SuppressWarnings({ }) public String getBar() { return bar; } </code></pre> <p>As you can see, i want to annotate "bar" field. Please advise. Ask for more if needed.</p> <p>[1] <a href="https://stackoverflow.com/questions/7343478/generate-indexed-annotation-using-jaxb-or-hyperjaxb">Generate @Indexed annotation using Jaxb or HyperJaxb</a><br/> [2] For sample see @Id annotation of Morphia</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload