I’m starting learning JAXB, so my question can be very silly. Now I have classes and want generate XML Schema. Going after this instruction I get exception
IllegalAnnotationExceptions … does not have a no-arg default
constructor.
Yeah. My classes haven’t default no-arg constructors. It’s too easy. I have classes with package visible constructors / final methods and off course with arguments. What shall I do – create some specific momemto/builder classes or specify my constructors to JAXB (in what way?) ? Thanks.
JAXB can support this case using an XML Adapter. Consider you have the following object with no zero-arg constructor:
You simply need to create a mappable version of this class:
And an XML Adapter to convert between them:
Then for properties that refer to the Customer class, simply use the @XmlJavaTypeAdapter annotation:
For a more detailed example see: