Commit 01b2a1de by Patryk Czarnik

Adnotacje JAXB

parent df748dc0
...@@ -2,11 +2,17 @@ package sklep.model; ...@@ -2,11 +2,17 @@ package sklep.model;
import java.util.Objects; import java.util.Objects;
import jakarta.xml.bind.annotation.XmlAttribute;
import jakarta.xml.bind.annotation.XmlElement;
public class Customer { public class Customer {
@XmlAttribute
private String email; private String email;
private String name; private String name;
@XmlElement(name="phone")
private String phoneNumber; private String phoneNumber;
private String address; private String address;
@XmlElement(name="postal-code")
private String postalCode; private String postalCode;
private String city; private String city;
......
package sklep.model;
import java.time.LocalDateTime;
import jakarta.xml.bind.annotation.adapters.XmlAdapter;
public class LocalDateTimeAdapter extends XmlAdapter<String, LocalDateTime> {
@Override
public LocalDateTime unmarshal(String s) throws Exception {
return LocalDateTime.parse(s);
}
@Override
public String marshal(LocalDateTime dt) throws Exception {
return dt.toString();
}
}
...@@ -7,11 +7,27 @@ import java.util.Collections; ...@@ -7,11 +7,27 @@ import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
import jakarta.xml.bind.annotation.XmlAttribute;
import jakarta.xml.bind.annotation.XmlElement;
import jakarta.xml.bind.annotation.XmlElementWrapper;
import jakarta.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
public class Order { public class Order {
@XmlAttribute(name="id")
private Integer orderId; private Integer orderId;
@XmlAttribute(name="customer-email")
private String customerEmail; private String customerEmail;
@XmlElement(name="order-date")
@XmlJavaTypeAdapter(LocalDateTimeAdapter.class)
private LocalDateTime orderDate; private LocalDateTime orderDate;
@XmlAttribute(name="status")
private Status orderStatus; private Status orderStatus;
@XmlElementWrapper(name="products")
@XmlElement(name="product")
public final List<OrderProduct> products = new ArrayList<>(); public final List<OrderProduct> products = new ArrayList<>();
public Order() { public Order() {
......
...@@ -3,10 +3,20 @@ package sklep.model; ...@@ -3,10 +3,20 @@ package sklep.model;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.Objects; import java.util.Objects;
import jakarta.xml.bind.annotation.XmlAttribute;
import jakarta.xml.bind.annotation.XmlElement;
import jakarta.xml.bind.annotation.XmlTransient;
public class OrderProduct { public class OrderProduct {
@XmlTransient
private Integer orderId; private Integer orderId;
@XmlAttribute(name="id")
private Integer productId; private Integer productId;
private int quantity; private int quantity;
@XmlElement(name="actual-price")
private BigDecimal actualPrice; private BigDecimal actualPrice;
public OrderProduct() { public OrderProduct() {
......
...@@ -3,8 +3,14 @@ package sklep.model; ...@@ -3,8 +3,14 @@ package sklep.model;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.Objects; import java.util.Objects;
import jakarta.xml.bind.annotation.XmlAttribute;
import jakarta.xml.bind.annotation.XmlElement;
public class Product { public class Product {
@XmlAttribute(name="id")
private Integer productId; private Integer productId;
@XmlElement(name="product-name")
private String productName; private String productName;
private BigDecimal price; private BigDecimal price;
private BigDecimal vat; private BigDecimal vat;
......
@XmlAccessorType(XmlAccessType.FIELD)
package sklep.model;
import jakarta.xml.bind.annotation.XmlAccessType;
import jakarta.xml.bind.annotation.XmlAccessorType;
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