JAXB generates Java classes without annotations

I am trying to create java classes from an xsd sample using the jdk 1.6, xjc command. But I don’t want to use annotations, that is, I don’t want the generated Java classes to contain annotations. How can i do this?

+4
source share
2 answers

In JAXB (JSR-222), the only standard representation of XML binding metadata defined in the standard is JAXB annotations. Therefore, the ability to generate classes without these annotations has limited use.

I am EclipseLink JAXB (MOXy) , and we offer the XML (and JSON) representation of JAXB metadata as an extension:

If you are interested in the ability to generate metadata instead of annotations, please request an improvement in our error database regarding the MOXy component:

0
source

This question has two parts:

  • At compile time, you need to generate your code differently. You can write an XJC plugin for this.
  • At run time, you should use a JAXB implementation that works without annotations (see Blaze's answer in this section).

Have a look at the XJC extensibility question:

XJC - extensibility?

You can write an XJC plugin that completely replaces code generation. Therefore, I can imagine an XJC plugin that generates XML mappings for MOXy instead of annotations in classes. You can also do this with JAXB RI using an optional annotation reader, but it is much more complicated than just using MOXy.

We will warn, however, that writing XJC advanced plugins is quite difficult for me.

0
source

Source: https://habr.com/ru/post/1443797/


All Articles