DEV Community

loizenai
loizenai

Posted on

How to resolve Json Infinite Recursion problem when working with Jackson

https://grokonez.com/json/resolve-json-infinite-recursion-problems-working-jackson

How to resolve Json Infinite Recursion problem when working with Jackson

Json Infinite Recursion is one of the most common problems when we serialize Java objects which having Bidirectional-Relationships. So in the tutorial JavaSampleApproach will show you how to smoothly handle the problems with Jackson annotations: @JsonIgnore, @JsonView, {@JsonManagedReference, @JsonBackReference} and @JsonIdentityInfo.

Related articles:

I. Infinite Recursion problem

We create 2 model classes: Company & Product have one-to-many relationship:

  • Company:

public class Company {
    private int id;
    private String name;
    private List products;
    
    public Company(){
    }
    ...
  • Product

public class Product {
    private int id;
    private String name;
    private Company company;
    
    public Product(){
    }

Serialize Java Objects with segment code:

More at:

https://grokonez.com/json/resolve-json-infinite-recursion-problems-working-jackson

How to resolve Json Infinite Recursion problem when working with Jackson

Top comments (0)