1

I have a dir /schemas that has many .xsd files, and I want to annotate every field of type String with a custom annotation I created.

I'm using this plugin: "org.jvnet.jaxb2_commons:jaxb2-basics-annotate:0.6.4".

I think creating a jaxb binding config would be my ideal solution. I tried this:

<jaxb:bindings>
    <jaxb:bindings node="xs:element[@type='xs:string']">
        <annox:annotateClass>@com.myapp.model.CustomAnnotation</annox:annotateClass>
    </jaxb:bindings>
</jaxb:bindings>

But in vain. Can you help? Thank you

lexicore
  • 42,748
  • 17
  • 132
  • 221
Yaz
  • 17,126
  • 3
  • 16
  • 11
  • Describe "in vain". – lexicore Jun 06 '18 at 19:25
  • You probably want an XPath like `//xs:element[@type='xs:string']`. Also you'll need `multiple="true"` on your `jaxb:bindings`. – lexicore Jun 06 '18 at 19:26
  • Also, `0.6.4` is a pretty old version. Latest are `1.0.4` and `1.1.0`. – lexicore Jun 06 '18 at 19:26
  • hey @lexicore thanks. I'm now trying to annotate just one field in one specific schema: ` @com.app.custom.MyAnnotation ` but unfortunately getting this error: `compiler was unable to honor this annox:annotate customization. It is attached to a wrong place, or its inconsistent with other bindings.` I'm pretty stuck now. Any advice? – Yaz Jun 07 '18 at 15:39
  • You have to make sure that you attach these customizations to the right place. Make sure your XPath is correct. – lexicore Jun 07 '18 at 16:58
  • I think the XPath is correct. From the error message, the line numbers are correct. `[ant:xjc] [ERROR] compiler was unable to honor this annox:annotate customization. It is attached to a wrong place, or its inconsistent with other bindings. [ant:xjc] line 53 of file:/some/path/mybinding.xjb [ant:xjc] [ant:xjc] [ERROR] (the above customization is attached to the following location in the schema) [ant:xjc] line 167 of file:/some/other/path/myschema.xsd` – Yaz Jun 07 '18 at 18:02
  • Please post a [MCVE]. Alternatively send the MCVE as a pull request here: https://github.com/highsource/jaxb2-annotate-plugin-support, say under `s/someproject`. – lexicore Jun 28 '18 at 08:15

0 Answers0