I am new to JAXB and it seems to be pretty straightforward but I have this XML (at the bottom of this post) and I want to map it to one "StorageArray" java object. Each StorageArray object will have many "HostStorageDomain" objects and each one of those may have zero to many "WWN" objects.
Another issue that I may have is, I already have the fields set from a different source for the "StorageArray" class. Everything except the HostStorageDomain and WWN is present, so I don't really need to map StorageArray but I do need the children elements since that is new information I want to map. I'm pulling the storagearray information from a CSV and when I start parsing this XML that data will be populated (and it has other data too). So I don't know if I need to modify the StorageArray class with JAXB annotations?
Also, Do I need to make a class for HostStorageDomain AND WWN? I don't care about the DvMCLIResult or CommandResult.
<?xml version="1.0" encoding="UTF-8"?>
<DvMCLIResult version="7.4.0-00">
<CommandResult command="GetSystemData">
<StorageArray objectID="ObjectID1" name="name1" description="Description1" serialNumber="87010488" arrayFamily="arrayModle" arrayType="arrayType" productName="productName" controllerVersion="controllerVersion" numberOfControllers="2" capacityInGB="96287" distributedMode="-1" >
<HostStorageDomain objectID="HSDOMAINID1" portID="0" portName="portName1" domainID="0" hostMode="Standard" hostMode2="" displayName="portName1" domainType="1" iSCSIName="iSCSIName1" nickname="nickname1" />
<HostStorageDomain objectID="HSDOMAINID2" portID="1" portName="portName2" domainID="0" hostMode="Standard" hostMode2="" displayName="portName2" domainType="1" iSCSIName="iSCSIName2" nickname="nickname2" >
<WWN nickname="WWName1" WWN="123456"/>
<WWN nickname="WWName2" WWN="234567"/>
<WWN nickname="WWName3" WWN="346578"/>
</HostStorageDomain>
<HostStorageDomain objectID="HSDOMAINID3" portID="16" portName="portName3" domainID="0" hostMode="Standard" hostMode2="" displayName="portName3" domainType="1" iSCSIName="iSCSIName3" nickname="nickname3" />
<HostStorageDomain objectID="HSDOMAINID4" portID="20" portName="portName4" domainID="0" hostMode="Standard" hostMode2="" displayName="portName2" domainType="0" nickname="nickname4" >
<WWN nickname="WWName4" WWN="342523"/>
</HostStorageDomain>
</StorageArray>
</CommandResult>
</DvMCLIResult>
EDIT:
Following Stephen Carlsons answer -- which seems to be working and I will accept is that I'm getting an error:
javax.xml.bind.UnmarshalException: unexpected element (uri:"", local:"DvMCLIResult"). Expected elements are <{}HostStorageDomain>,<{}Path>,<{}StorageArray>,<{}WWN>
I have a storage class that starts like this and contains the HostStorageDomain Class -- StorageDomains
@XmlRootElement(name = "StorageArray")
@XmlAccessorType(XmlAccessType.NONE) // Only specifying the fields I want with annotations
public class Storage implements Serializable {
...
@XmlElement(name = "HostStorageDomain")
List<StorageDomain> domains = new ArrayList<StorageDomain>();
In a translator class, I am performing the unmarshalling like this
JAXBContext context = JAXBContext.newInstance(Storage.class);
Unmarshaller unmarshaller = context.createUnmarshaller();
storage = (Storage) unmarshaller.unmarshal(is); // Inputstream of the xml String
Any ideas?