Hi,
I have generated java classes using JAXB maven plugin from my xsd file.
Now I am trying to generate xml using the generated classes. The problem is that the generated xml is not complete.
@XmlAccessorType(XmlAccessType.FIELD) @XmlType(name = "", propOrder = { "generalSeg", "bolSeg" }) @XmlRootElement(name = "amds") public class Amds { @XmlElement(name = "General_seg", required = true) protected amds.generalSeg generalSeg; @XmlElement(name = "Bol_seg") protected List<amds.bolSeg> bolSeg; public Amds.generalSeg getgeneralSeg() { return generalSeg; } /** * Sets the value of the generalSeg property. * * @param value * allowed object is * {@link Amds.generalSeg } * */ public void setgeneralSeg(Amds.generalSeg value) { this.generalSeg = value; } public List<Amds.bolSeg> getbolSeg() { if (bolSeg == null) { bolSeg = new ArrayList<amds.bolSeg>(); } return this.bolSeg; }
Below is the class used to generate xml
Amds amds= new Amds(); Amds.generalSeg generalSeg=new Amds.generalSeg(); amds.setgeneralSeg(generalSeg); Amds.generalSeg.generalSegId generalSegId= new Amds.generalSeg.generalSegId(); generalSeg.setgeneralSegId(generalSegId); generalSegId.setCode("EN1400"); generalSegId.setVoyageNumber("VOY123"); Amds.generalSeg.TotalsSegment totalsSegment= new Amds.generalSeg.TotalsSegment(); generalSeg.setTotalsSegment(totalsSegment); totalsSegment.setTotalNumberOfBols(1); Amds.bolSeg bolSeg = new Amds.bolSeg(); Amds.bolSeg.BolId bolId = new Amds.bolSeg.BolId(); bolSeg.setBolId(bolId); bolId.setBolRef("1234"); bolId.setBolType("201"); Amds.bolSeg.GoodsSegment goodsSegment = new Amds.bolSeg.GoodsSegment(); bolSeg.setGoodsSegment(goodsSegment); goodsSegment.setNumberOfPackages(2); goodsSegment.setPackageTypeCode("21"); Amds.getbolSeg().add(bolSeg); JAXBContext context = JAXBContext.newInstance(Amds.class); Marshaller jaxbMarshaller = context.createMarshaller(); jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); QName qName = new QName("", "amds"); JAXBElement<amds> root = new JAXBElement<>(qName, Amds.class, amds); System.out.println(root.getValue().getbolSeg()); jaxbMarshaller.marshal(root, System.out);
Below is result: It is not generating the bolSeg part
<amds>
<generalSeg>
<generalSegId>
<Code>EN1400</Code>
<voyageNumber>VOY123</voyageNumber>
</generalSegId>
<totalsSegment>
<totalNumberOfBols>1</totalNumberOfBols>
</totalsSegment>
</generalSeg>
</amds>