Community
Participate
Working Groups
JAXB allows a factory class and method to be specified via the @XmlType annotation: @XmlType( propOrder={"name", "address", "phoneNumbers"}, factoryClass=CustomerFactory.class, factoryMethod="createCustomer") public class Customer { } The factory method is expected to be a 0-arg static or instance method. This requires the user to have a unique factory method per type. Enhancement ----------- In addition to checking for a 0-arg method, check for a method with a singe arg of type Class. When calling this factory method the domain model class would be passed in as a parameter. This would allow you to do: @XmlType( factoryClass=CommonFactory.class, factoryMethod="create") public class Customer { } @XmlType( factoryClass=CommonFactory.class, factoryMethod="create") public class Address { } public class CommonFactory { public static Object create(Class clazz) { if(Customer.class == clazz) { ... } else if(Address.class == clazz) { ... } } }
MOXy specific workaround http://stackoverflow.com/questions/8026502/parametrizing-jaxb-factory-methods-with-class-to-create/8053628#8053628
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink