I have to build an XML containing several elements. I have such elements to build this XML part
<ram:SpecifiedLineTradeAgreement>
<ram:BuyerOrderReferencedDocument>
<ram:LineID>1</ram:LineID>
</ram:BuyerOrderReferencedDocument>
<ram:NetPriceProductTradePrice>
<ram:ChargeAmount>60.0000</ram:ChargeAmount>
<ram:BasisQuantity unitCode="C62">1.0000</ram:BasisQuantity>
</ram:NetPriceProductTradePrice>
</ram:SpecifiedLineTradeAgreement>
I created POJOs for SpecifiedLineTradeAgreement, BuyerOrderReferencedDocument, NetPriceProductTradePrice...
@Getter @Setter
@XmlAccessorType(XmlAccessType.FIELD)
public class SpecifiedLineTradeAgreement {
@XmlElement(name = "BuyerOrderReferencedDocument", namespace = NamespaceMapper.RAM_URI)
private BuyerOrderReferencedDocument buyerOrderReferencedDocument;
@XmlElement(name = "NetPriceProductTradePrice", namespace = NamespaceMapper.RAM_URI)
private NetPriceProductTradePrice netPriceProductTradePrice;
}
@Getter @Setter
@XmlAccessorType(XmlAccessType.FIELD)
public class BuyerOrderReferencedDocument {
@XmlElement(name = "LineID", namespace = NamespaceMapper.RAM_URI)
private String lineId;
}
@Getter @Setter
@XmlAccessorType(XmlAccessType.FIELD)
public class NetPriceProductTradePrice {
@XmlElement(name = "ChargeAmount", namespace = NamespaceMapper.RAM_URI)
private String chargeAmount;
@XmlElement(name = "BasisQuantity", namespace = NamespaceMapper.RAM_URI)
private String basisQuantity;
}
My issue is concerning <ram:BasisQuantity unitCode="C62">1.0000</ram:BasisQuantity>
I found that we can use XMLAttribute annotation
@Getter @Setter
@XmlAccessorType(XmlAccessType.FIELD)
public class IssueDateTime {
@XmlElement(name = "DateTimeString", namespace = NamespaceMapper.UDT_URI)
private String dateTimeString;
@XmlAttribute(name="format")
private int format;
}
It generates this
<ram:IssueDateTime format="102">
<udt:DateTimeString>20200115</udt:DateTimeString>
</ram:IssueDateTime>
Unfortunatelly, it's not exactly what i'm expecting.