Community
Participate
Working Groups
Use Case: - You have multiple JAXBContexts and each context, and there is a subset of classes that are common to all of the JAXBContexts. Current Behaviour: - Each MOXy JAXBContext would have a copy of the metadata for those common classes. Proposal: - Allow a JAXBContext to be defined for the common set of classes. Then allow new contexts to be created that are able to share the metadata defined in this common JAXBContext.
Created attachment 191937 [details] MOXy - Fix
This would allow a user to do something like: package memory; import java.util.HashMap; import java.util.Map; import javax.xml.bind.JAXBContext; import javax.xml.bind.Marshaller; import org.eclipse.persistence.jaxb.JAXBContextFactory; import org.eclipse.persistence.jaxb.JAXBHelper; public class Demo { public static void main(String[] args) throws Exception { JAXBContext addressJC = JAXBContext.newInstance(Address.class); Map<String, Object> customerJCProperties = new HashMap<String, Object>(); customerJCProperties.put(JAXBContextFactory.PARENT_CONTEXT_KEY, addressJC); JAXBContext customerJC = JAXBContext.newInstance(new Class[] {Customer.class}, customerJCProperties); Map<String, Object> purchaseOrderJCProperties = new HashMap<String, Object>(); purchaseOrderJCProperties.put(JAXBContextFactory.PARENT_CONTEXT_KEY, customerJC); JAXBContext purchaseOrderJC = JAXBContext.newInstance(new Class[] {PurchaseOrder.class}, purchaseOrderJCProperties); PurchaseOrder po = new PurchaseOrder(); Address shippingAddress = new Address(); shippingAddress.setStreet("456 B Road"); po.setShippingAddress(shippingAddress); Customer customer = new Customer(); Address billingAddress = new Address(); billingAddress.setStreet("123 A Street"); customer.setBillingAddress(billingAddress); po.setCustomer(customer); Marshaller poMarshaller = purchaseOrderJC.createMarshaller(); poMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); poMarshaller.marshal(po, System.out); System.out.println(JAXBHelper.getJAXBContext(addressJC).getXMLDescriptor(Address.class) == JAXBHelper.getJAXBContext(purchaseOrderJC).getXMLDescriptor(Address.class)); } }
Created attachment 192018 [details] MOXy - Fix
Created attachment 192039 [details] MOXy - Fix
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink