Commit 90f7865c by Patryk Czarnik

poprawki dot eksportu JSON, m.in. @JsonIgnore

parent cfe8a578
...@@ -7,6 +7,8 @@ import jakarta.validation.constraints.Pattern; ...@@ -7,6 +7,8 @@ import jakarta.validation.constraints.Pattern;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
import java.util.Set; import java.util.Set;
import com.fasterxml.jackson.annotation.JsonIgnore;
@Entity @Entity
@Table(name = "customers") @Table(name = "customers")
public class Customer { public class Customer {
...@@ -32,6 +34,9 @@ public class Customer { ...@@ -32,6 +34,9 @@ public class Customer {
private String city; private String city;
@OneToMany(mappedBy = "customer") @OneToMany(mappedBy = "customer")
@JsonIgnore
// W danych klienta zwracanych w JSONie nie będzie listy zamówień.
// Można by pomyśleć o stworzeniu dwóch wersji tej klasy - jedna z zamówieniami, jedna bez.
private Set<Order> orders = new LinkedHashSet<>(); private Set<Order> orders = new LinkedHashSet<>();
public String getCustomerEmail() { public String getCustomerEmail() {
......
...@@ -16,7 +16,7 @@ public class Order { ...@@ -16,7 +16,7 @@ public class Order {
@Column(name = "order_id", nullable = false) @Column(name = "order_id", nullable = false)
private Integer id; private Integer id;
@ManyToOne(fetch = FetchType.LAZY, optional = false) @ManyToOne( optional = false)
@JoinColumn(name = "customer_email", nullable = false) @JoinColumn(name = "customer_email", nullable = false)
private Customer customer; private Customer customer;
......
...@@ -5,6 +5,8 @@ import jakarta.validation.constraints.Min; ...@@ -5,6 +5,8 @@ import jakarta.validation.constraints.Min;
import org.hibernate.annotations.ColumnDefault; import org.hibernate.annotations.ColumnDefault;
import com.fasterxml.jackson.annotation.JsonIgnore;
import java.math.BigDecimal; import java.math.BigDecimal;
@Entity @Entity
...@@ -16,6 +18,7 @@ public class OrderProduct { ...@@ -16,6 +18,7 @@ public class OrderProduct {
@MapsId("orderId") @MapsId("orderId")
@ManyToOne(fetch = FetchType.LAZY, optional = false) @ManyToOne(fetch = FetchType.LAZY, optional = false)
@JoinColumn(name = "order_id", nullable = false) @JoinColumn(name = "order_id", nullable = false)
@JsonIgnore
private Order order; private Order order;
@MapsId("productId") @MapsId("productId")
......
...@@ -6,4 +6,6 @@ spring.datasource.url=jdbc:postgresql://localhost/sklep ...@@ -6,4 +6,6 @@ spring.datasource.url=jdbc:postgresql://localhost/sklep
spring.datasource.username=alx spring.datasource.username=alx
spring.datasource.password=abc123 spring.datasource.password=abc123
spring.jackson.serialization.FAIL_ON_EMPTY_BEANS=false
alx.photo_dir=/home/patryk/sklep/foto alx.photo_dir=/home/patryk/sklep/foto
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