For Example I have a sample Java object and want to marshal
@XmlElement(name = "itemName")
private String name;
@XmlElement(name = "quantity")
private int quantity;
@XmlElement(name = "Price")
private String price;
@XmlElement(name = "totalPrice")
private String total;
Here I want marshal such a way that multiply quantity with Price and want to assign that value to totalPrice
How can we achieve this using Jaxb? Can anyone help on this
答案 0 :(得分:0)
通过添加
解决了这个问题 @XmlElement(name = "totalPrice")
private String getTotal(){
return String.valueOf(Integer.parseInt(this.getPrice()) + this.getQuantity());
}
并删除
@XmlElement(name = "totalPrice")
private String total;