Affects Version/s: 2.2.7
Fix Version/s: None
JAXB implementation does not allow a generic factory method. Let's take a look at this simple example:
Example provided above is impossible to implement in current JAXB. The problem here is that you either let JAXB invoke no-arg constructor of CalculatorInput class or explicit static factory method inside this class or in specific factory class. Note that you must have one factory method per class which is extremely bulky, not object-oriented, boilerplate, blah blah blah. Basically it's a mistake.
I know better than JXAB how to create my objects - I need JAXB only to fill these beans with parsed XML content.
Another argument is that JAXB in the current state completely ignores existence of Dependency Injection (which is a part of Java EE specification). In case JAXB creates my CalculatorInput, someContext attribute will be ignored (thus null) by DI container as it has absolutely no knowledge on this instance. The only correct way to make the injection work is to obtain the new instance from the DI bean / object factory - see IocContainerObjectFactory. OK, it is possible but only in such form (again, bulky, boilerplate, ugly):
Imagine what happens if you have more than couple of beans...
JavaDoc of javax.xml.bind.annotation.XmlType says:
But, the JSR-222 specification does not explicitly say that it must be a no-arg factory method.
Please correct me if I'm wrong.