src/main/java/com/wpollock/jaxbdemo/Product.java

package com.wpollock.jaxbdemo;

import javax.xml.bind.annotation.*;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import java.math.BigDecimal;


@XmlRootElement(name = "product")
@XmlAccessorType(XmlAccessType.FIELD)
public class Product {
    @XmlAttribute(name = "id")
    private String productId;
    @XmlElement(name = "description")
    private String description;
    @XmlElement(name = "imageUrl")
    private String imageUrl;
    @XmlElement(name = "price")
    @XmlJavaTypeAdapter(DoubleAdapter.class)
    private BigDecimal price;
    @XmlElement(name = "createdBy")
    private User createdBy;
    public Product(){}
    public Product(String productId, String description, String imageUrl,
                   BigDecimal price, User createdBy) {
        this.productId = productId;
        this.description = description;
        this.imageUrl = imageUrl;
        this.price = price;
        this.createdBy = createdBy;
    }

    @Override
    public String toString() {
        return String.format("Product{\n"
                + " productId='%s',\n"
                + " description='%s',\n"
                + " imageURL='%s',\n"
                + " price=%.2f,\n"
                + " createdBy='%s'\n}",
                productId, description, imageUrl, price, createdBy);
    }
}