spring boot jackson infinite recursion

Solutions on MaxInterview for spring boot jackson infinite recursion by the best coders in the world

showing results for - "spring boot jackson infinite recursion"
Neal
27 May 2016
1// some solutions:
2
3public class Product {
4    @NotNull
5    @ManyToOne(cascade = {CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH}, fetch = FetchType.LAZY)
6    @JoinColumn(name = "category_id", nullable = false)
7    @JsonBackReference
8    private Category category;
9}
10
11public class Category {
12    @OneToMany(cascade=CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "category")
13    @JsonManagedReference
14    private List<Product> products  = new ArrayList<>();
15}
16
17// ______________________________________________
18
19@JsonIdentityInfo(
20  generator = ObjectIdGenerators.PropertyGenerator.class, 
21  property = "id")
22public class Product {
23    ...
24}
25
26@JsonIdentityInfo(
27  generator = ObjectIdGenerators.PropertyGenerator.class, 
28  property = "id")
29public class Category {
30    ...
31}
32
33//________________________
34
35// Just use @JsonIgnore on one of the sides