Infinite Recursion with Jackson JSON and Hibernate JPA issue

前端 未结 25 3125
你的背包
你的背包 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条回答
  •  伪装坚强ぢ
    2020-11-21 07:54

    The new annotation @JsonIgnoreProperties resolves many of the issues with the other options.

    @Entity
    
    public class Material{
       ...    
       @JsonIgnoreProperties("costMaterials")
       private List costSuppliers = new ArrayList<>();
       ...
    }
    
    @Entity
    public class Supplier{
       ...
       @JsonIgnoreProperties("costSuppliers")
       private List costMaterials = new ArrayList<>();
       ....
    }
    

    Check it out here. It works just like in the documentation:
    http://springquay.blogspot.com/2016/01/new-approach-to-solve-json-recursive.html

提交回复
热议问题