Product.java
Download Product.java
1: package com.wpollock.jaxbdemo;
2:
3: import javax.xml.bind.annotation.*;
4: import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
5: import java.math.BigDecimal;
6:
7:
8: @XmlRootElement(name = "product")
9: @XmlAccessorType(XmlAccessType.FIELD)
10: public class Product {
11: @XmlAttribute(name = "id")
12: private String productId;
13: @XmlElement(name = "description")
14: private String description;
15: @XmlElement(name = "imageUrl")
16: private String imageUrl;
17: @XmlElement(name = "price")
18: @XmlJavaTypeAdapter(DoubleAdapter.class)
19: private BigDecimal price;
20: @XmlElement(name = "createdBy")
21: private User createdBy;
22: public Product(){}
23: public Product(String productId, String description, String imageUrl,
24: BigDecimal price, User createdBy) {
25: this.productId = productId;
26: this.description = description;
27: this.imageUrl = imageUrl;
28: this.price = price;
29: this.createdBy = createdBy;
30: }
31:
32: @Override
33: public String toString() {
34: return String.format("Product{\n"
35: + " productId='%s',\n"
36: + " description='%s',\n"
37: + " imageURL='%s',\n"
38: + " price=%.2f,\n"
39: + " createdBy='%s'\n}",
40: productId, description, imageUrl, price, createdBy);
41: }
42: }