Answers for "spring boot jackson infinite recursion"

0

spring boot jackson infinite recursion

// some solutions:

public class Product {
    @NotNull
    @ManyToOne(cascade = {CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH}, fetch = FetchType.LAZY)
    @JoinColumn(name = "category_id", nullable = false)
    @JsonBackReference
    private Category category;
}

public class Category {
    @OneToMany(cascade=CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "category")
    @JsonManagedReference
    private List<Product> products  = new ArrayList<>();
}

// ______________________________________________

@JsonIdentityInfo(
  generator = ObjectIdGenerators.PropertyGenerator.class, 
  property = "id")
public class Product {
    ...
}

@JsonIdentityInfo(
  generator = ObjectIdGenerators.PropertyGenerator.class, 
  property = "id")
public class Category {
    ...
}

//________________________

// Just use @JsonIgnore on one of the sides
Posted by: Guest on May-08-2021

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language