Skip to main content
Jump to: navigation, search


< EclipseLink‎ | Examples‎ | MOXy‎ | Dynamic


In this example you will learn how to unmarshal dynamic entities from XML.

Unmarshal DynamicEntities from XML

The Unmarshaller obtained from the DynamicJAXBContext is a standard unmarshaller, and can be used normally to unmarshal instances of DynamicEntity.

FileInputStream xmlInputStream = new FileInputStream("src/example/dynamic/customer.xml");
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
DynamicEntity customer = (DynamicEntity) unmarshaller.unmarshal(xmlInputStream);

Get Data from the DynamicEntity

DynamicEntity offers property based data access, get("name") instead of getName().


Get Data using DynamicType

Instances of DynamicEntity have a corresponding DynamicType. DynamicType can be used to introspec the DynamicEntity.

DynamicType addressType = jaxbContext.getDynamicType("org.example.Address");
DynamicEntity address = customer.<DynamicEntity>get("address");
for(String propertyName: addressType.getPropertiesNames()) {

XML Document

Below is a sample XML document for this example.

<?xml version="1.0" encoding="UTF-8"?>
<customer xmlns="">
   <name>Jane Doe</name>
      <street>1 Any Street</street>
      <city>Any Town</city>

Next Steps

Next we will learn how to marshal instances of DynamicEntity to XML, seeDynamicEntity to XML.

Back to the top