Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

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
Comment

PREVIOUS NEXT
Code Example
Java :: react The href attribute is required for an anchor to be keyboard 
Java :: javafx main class 
Java :: intellij 
Java :: hashmap to list java 
Java :: load a list from text file java 
Java :: java constructor chaining 
Java :: arraylist reverse in java 
Java :: repository query spring boot 
Java :: android view set border programmatically 
Java :: how to fill a 2d array in java 
Java :: java declare a list 
Java :: java currency format 
Java :: loop through treeset java 
Java :: this keyword in java 
Java :: how to conver string to int 
Java :: how to center a window in java 
Java :: login and logout react native and firebase 
Java :: max and min array number in java 
Java :: radio button in java 
Java :: how to go to next iteration of while loop java 
Java :: code to include layout from java in android 
Java :: java collection interface 
Java :: check if char is a space java 
Java :: jtable font size 
Java :: java program to remove duplicate words in a string 
Java :: maven set java version 
Java :: java instanceof 
Java :: java to the power of 
Java :: java remove first character 
Java :: multiple condition inside for loop java 
ADD CONTENT
Topic
Content
Source link
Name
9+2 =