javajaxbmaven-jaxb2-plugin

How to advise maven-jaxb2-plugin to use same class in two places?


I'm using maven-jaxb2-plugin to generate JAXB classes. I have no control over the WSDL or XSD.

The XSD specifies either a single "MyObject", or a parent object containing a list of "MyObjects". I know they're the same. But the plugin doesn't (naturally). Is there a way I can tell it to use a single (non-inner) class for both? Otherwise, I would need to write lots of duplicate code...

Thanks!


Solution

  • Yes, you can control using bindings, for example here and you can force to be use same class (you'll get a warning since they are redefined).

    Anyway, probably you are using a wrong generated WSDL/XSD with multiple namespaces (e.g. they use the same codebase but are exposing multiple endpoints, for them is the same class but for you are multiple different classes).

    Although you "have no control over the WSDL" ask for fix it, if not, maybe you can unify (writing one script into your CI/CD pipeline) putting all of them together (e.g. multiple xsd inside one root).

    Unfortunately many people write and publish web services incorrectly and produce a lot of (unnecessary) headaches for those of us who use them :/