Jackson Circular Dependencies

后端 未结 2 711
萌比男神i
萌比男神i 2021-01-12 14:43

I have a circular dependency that I am struggling to solve right now Take these two classes - boiler plate code removed for demo purposes

Class 1

@En         


        
相关标签:
2条回答
  • 2021-01-12 15:14

    I went with the annotation below in the end

    @JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id")
    

    Thanks for your help guys

    0 讨论(0)
  • 2021-01-12 15:37

    if you are using Jackson HttpMessageConverter, you should check their documentation - http://wiki.fasterxml.com/JacksonFeatureBiDirReferences

    You should add annotations shown here:

    public class NodeList
    {
        @JsonManagedReference
        public List<NodeForList> nodes;
    }
    
    public class NodeForList
    {
        public String name;
    
        @JsonBackReference public NodeList parent;
    
        public NodeForList() { this(null); }
        public NodeForList(String n) { name = n; }
    }
    
    0 讨论(0)
提交回复
热议问题