JAXB-XJC: Add required args constructor for all generated classes by jaxb2-maven-plugin

208 Views Asked by At

Is there a way to add a required args constructor for org.codehaus.mojo:jaxb2-maven-plugin?

I found org.jvnet.jaxb2_commons:jaxb2-value-constructor but it can only generate all args constructor for all generated classes.

Or can I annotate each generated class somehow with Lomboks @RequiredArgsConstructor afterwards?

Looked for plugin extensions.

2

There are 2 best solutions below

0
Laurent Schoelens On

Maybe you could use the JAXB Annotate plugin which allow you to add any annotation on any class / field.

1
Rick O'Sullivan On

In the next release of HiSrc BasicJAXB, the ValueConstructorPlugin will provide these XJC options:

  • XvalueConstructor-complete - generate constructors for the complete set of fields.
  • XvalueConstructor-required - generate constructors for all required fields.
  • XvalueConstructor-selected - generate constructors for selector constraints: key, keyref and unique.

Disclaimer: I am the maintainer for the forked HiSrc BasicJAXB project.