0

I am using Jackson 2.3 and I am getting Jackon infinite recursion error.

Class A

public class A{

    @OneToMany(mappedBy = "parent")
    @LazyCollection(LazyCollectionOption.FALSE)
    //option2: @JsonManagedReference
    private List<B> listMembers;

    public List<B> getListMembers(){
        return this.listMembers;
    }

    public void setListMembers(List<B> listMembers){
        this.listMembers = listMembers;
    }
}

Class B

public class B{

    @ManyToOne(cascade = CascadeType.REFRESH)
    @JoinColumn(name = "a_id")
    // Option1: @JsonIgnore
    // Option2: @JsonBackReference
    private A parent;

    public A getParent(){
        return this.parent;
    }

    public void setParent(A parent){
        this.parent = parent;
    }
}

I have tried following options

1st option is in class B on property parent put @JsonIgnore annotation.

2nd option is in class A on property listMembers put @JsonManagedReference and in class B on property parent put @JsonBackReference.

I am still getting this problems.

This jar files I am using are

  • jackson-annotations-2.3.0.jar
  • jackson-core-2.3.2.jar
  • jackson-databind-2.3.2.jar

Kindly help.

Rüdiger Herrmann
  • 20,512
  • 11
  • 62
  • 79
Priyank Thakkar
  • 4,752
  • 19
  • 57
  • 93
  • Could you please post the stack traces in the option 1 and 2? – Gregor Raýman Apr 07 '15 at 14:24
  • @GregorRaýman: for option 1 org.springframework.web.servlet.DispatcherServlet processRequest Could not complete request org.springframework.http.converter.HttpMessageNotWritableException: Could not write JSON: Infinite recursion (StackOverflowError) (through reference chain: com.priyank.app.domain.B["parent"]->com.priyank.app.domain.A["listMembers"]->org.hibernate.collection.internal.PersistentBag[0]->com.priyank.app.domain.B["parent"]->com.priyank.app.domain.A["listMembers"]->org.hibernate.collection.internal.PersistentBag[0]-and so on rest is 90k characters but repeats the same – Priyank Thakkar Apr 07 '15 at 14:44
  • @GregorRaýman: for option2 also it is same :( – Priyank Thakkar Apr 07 '15 at 14:51
  • this is very strange. are the classes really recompiled? are the annotations on the classpath? – Gregor Raýman Apr 07 '15 at 15:39

0 Answers0