Commit 200d3419 by Patryk Czarnik

Adnotacje JAXB

parent 0ef1da81
package sklep.model;
import java.time.LocalDateTime;
import javax.xml.bind.annotation.adapters.XmlAdapter;
public class DateTimeAdapter extends XmlAdapter<String, LocalDateTime> {
@Override
public LocalDateTime unmarshal(String s) {
return LocalDateTime.parse(s);
}
@Override
public String marshal(LocalDateTime dt) {
return dt.toString();
}
}
......@@ -7,11 +7,27 @@ import java.util.Collections;
import java.util.List;
import java.util.Objects;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
public class Order {
@XmlAttribute(name="id")
private Integer orderId;
@XmlAttribute(name="customer-email")
private String customerEmail;
@XmlElement(name="order-date")
@XmlJavaTypeAdapter(DateTimeAdapter.class)
private LocalDateTime orderDate;
@XmlAttribute(name="status")
private Status orderStatus;
@XmlElementWrapper(name="products")
@XmlElement(name="product")
public final List<OrderProduct> products = new ArrayList<>();
public Order() {
......
......@@ -3,10 +3,19 @@ package sklep.model;
import java.math.BigDecimal;
import java.util.Objects;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
public class OrderProduct {
@XmlAttribute(name="order-id")
private Integer orderId;
@XmlAttribute(name="product-id")
private Integer productId;
private int quantity;
@XmlElement(name="actual-price")
private BigDecimal actualPrice;
public OrderProduct() {
......
......@@ -3,13 +3,16 @@ package sklep.model;
import java.math.BigDecimal;
import java.util.Objects;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
@XmlAccessorType(XmlAccessType.FIELD)
public class Product {
@XmlAttribute(name="id")
private Integer productId;
@XmlElement(name="product-name")
private String productName;
private BigDecimal price;
private BigDecimal vat;
private String description;
......@@ -34,7 +37,7 @@ public class Product {
}
public String getProductName() {
return productName.toUpperCase();
return productName;
}
public void setProductName(String productName) {
......@@ -45,16 +48,8 @@ public class Product {
return price;
}
// public void setPrice(BigDecimal price) {
// this.price = price;
// }
public String getNiespodzianka() {
return "a kuku";
}
public void setNiespodzianka(String x) {
public void setPrice(BigDecimal price) {
this.price = price;
}
public BigDecimal getVat() {
......
@XmlAccessorType(XmlAccessType.FIELD)
package sklep.model;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
/* Technologia JAXB (Java Architecture for XML Binding)
* to zautomatyzowane tłumaczenie obiektów Javy do XML i w drugą stronę.
*
* Istnieją pewne domyślne ustawienia, które pozwalają konwertować dane od razu,
* a dodatkowo za pomocą adnotacji (@Xml????) można wpłynąć na nazwy itp. ustawienia.
*/
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment