Infinite Recursion with Jackson JSON and Hibernate JPA issue

前端 未结 25 3217
你的背包
你的背包 2020-11-21 07:31

When trying to convert a JPA object that has a bi-directional association into JSON, I keep getting

org.codehaus.jackson.map.JsonMappingException: Infinite          


        
25条回答
  •  Happy的楠姐
    2020-11-21 07:38

    For some reason, in my case, it wasn't working with Set. I had to change it to List and use @JsonIgnore and @ToString.Exclude to get it working.

    Replace Set with List:

    //before
    @OneToMany(mappedBy="client")
    private Set
    addressess; //after @OneToMany(mappedBy="client") private List
    addressess;

    And add @JsonIgnore and @ToString.Exclude annotations:

    @ManyToOne
    @JoinColumn(name="client_id", nullable = false)
    @JsonIgnore
    @ToString.Exclude
    private Client client;
    

提交回复
热议问题