Home JPA Hibernate limit recursion, json jackson breadth first
 I have a Abstract base class "BaseArticle" I use the scheme of having a table for each different class. I have two classes extending this: @Inheritance(strategy=InheritanceType.TABLE_PER_CLASS) @JsonIdentityInfo( generator = ObjectIdGenerators.PropertyGenerator.class, property = "id") @Entity public class ArticleA extends BaseArticle { .... } @Inheritance(strategy=InheritanceType.TABLE_PER_CLASS) @JsonIdentityInfo( generator = ObjectIdGenerators.PropertyGenerator.class, property = "id") @Entity public class ArticleB extends BaseArticle { .... }  (These have the inheritance attribute, cause they can also get extended, it's a bit more complex, but I'm just trying to highlight the issue) now my base article looks like this: @Entity @Inheritance(strategy=InheritanceType.TABLE_PER_CLASS) @JsonIdentityInfo( generator = ObjectIdGenerators.PropertyGenerator.class, property = "id") public abstract class BaseArticle implements Serializable{ ... @Id @GeneratedValue(strategy = GenerationType.TABLE) public Long id; @ManyToMany(fetch = FetchType.EAGER,cascade={CascadeType.ALL}) @JoinTable(name="recommendedarticle", joinColumns={@JoinColumn(name="baseart_id")}, inverseJoinColumns={@JoinColumn(name="recommended_id")}) @Size(min=0, max=6) @ElementCollection(targetClass=BaseArticle.class) public Set recommended; public Set getRecommended() { return recommended; } public void setRecommended(Set recommended) { this.recommended = recommended; } }  Now, I created the functions just to test if this would fix stuff, so it's currently a bit untidy. But the issue is, an article has multiple articles that can be recommended with it. I've ran into the following issues: @JsonIdentityInfo( generator = ObjectIdGenerators.PropertyGenerator.class, property = "id")  I've found this through the Docs, that this would make sure multiple articles wouldn't be loaded and cause cycles or errors, however this is a depth first way: the first article gets loaded, then the recommended of the first, then the recommended of the first recommended in that article, which leaves the output json like this: [ { title:"Article1", "recommended":[ art2,art3, etc. ] }, IDOFArt2, IDOFArt3, etc.. ]  So the issue is, it's doing depth first instead of breadth first. which is my first problem. The second problem is (which can also easily fix the first), I don't need the recommended articles of the recommended articles. Is there a way to limit this "depth" in json?