Commit 816d394c by Patryk Czarnik

Jednak bez JAXB

parent 0af10b16
package sklep.model;
import jakarta.xml.bind.annotation.adapters.XmlAdapter;
import java.time.LocalDateTime;
public class AdapterDaty extends XmlAdapter<String, LocalDateTime> {
@Override
public LocalDateTime unmarshal(String s) {
return LocalDateTime.parse(s);
}
@Override
public String marshal(LocalDateTime dt) {
return dt.toString();
}
}
package sklep.model; package sklep.model;
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;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
...@@ -13,21 +8,14 @@ import java.util.List; ...@@ -13,21 +8,14 @@ import java.util.List;
import java.util.Objects; import java.util.Objects;
public class Order { public class Order {
@XmlAttribute(name="id")
private Integer orderId; private Integer orderId;
@XmlElement(name="customer-email")
private String customerEmail; private String customerEmail;
@XmlElement(name="order-date")
@XmlJavaTypeAdapter(AdapterDaty.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() {
......
package sklep.model; package sklep.model;
import jakarta.xml.bind.annotation.XmlAttribute;
import jakarta.xml.bind.annotation.XmlElement;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.Objects; import java.util.Objects;
public class OrderProduct { public class OrderProduct {
@XmlAttribute(name="order-id")
private Integer orderId; private Integer orderId;
@XmlAttribute(name="product-id")
private Integer productId; private Integer productId;
private int quantity; private int quantity;
@XmlElement(name="price")
private BigDecimal actualPrice; private BigDecimal actualPrice;
public OrderProduct() { public OrderProduct() {
......
package sklep.model; package sklep.model;
import jakarta.xml.bind.annotation.XmlAttribute;
import jakarta.xml.bind.annotation.XmlElement;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.Objects; import java.util.Objects;
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;
\ No newline at end of file
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