Wednesday, December 30, 2020

Dynamic JAXB - XSD Using Dynamic Entities

https://www.eclipse.org/eclipselink/documentation/2.5/solutions/jpatoxml006.htm#BEIDHGHI

https://www.eclipse.org/eclipselink/documentation/

https://www.eclipse.org/eclipselink/documentation/3.0/moxy/toc.htm


With EclipseLink MOXy, you can provide an existing XML schema from which to create a DynamicJAXBContext. EclipseLink will parse the schema and generate DynamicTypes for each complex type


https://www.eclipse.org/eclipselink/documentation/3.0/moxy/dynamic_jaxb.htm#sthref194



InputStream inputStream = myClassLoader.getSystemResourceAsStream("example/resources/xsd/customer.xsd");

DynamicJAXBContext dContext = DynamicJAXBContextFactory.createContextFromXSD(inputStream, null, myClassLoader, null);

 

DynamicEntity newCustomer = dContext.newDynamicEntity("example.Customer");

newCustomer.set("firstName", "George");

newCustomer.set("lastName", "Jones");

 

DynamicEntity newAddress = dContext.newDynamicEntity("example.Address");

newAddress.set("street", "227 Main St.");

newAddress.set("city", "Toronto");

newAddress.set("province", "Ontario");

newAddress.set("postalCode", "M5V1E6"); 

newCustomer.set("address", newAddress);

 

dContext.createMarshaller().marshal(newCustomer, System.out);


No comments:

Post a Comment

Azure - Pipeline - Add Approver for Stage

https://learn.microsoft.com/en-us/azure/devops/pipelines/process/approvals?view=azure-devops&tabs=check-pass