In my Spring MVC application, I have three classes - content, category and document - all of them are interconnected and must be serialized in JSON, but at the same time cause an infinite loop. The relationship is:
Content -> List<Category> -> List<Document> -> List<Content> -> (etc.)
where Category is a property of Content, etc. I am trying to serialize it so that the link ends in a List (so that content.categories.documents appear in the view), but without finding any way to go This. Annotating with Jackson @JsonManagedReference and @JsonBackReference will not work, because some of these fields are already annotated as such for other relationships. You do not know how to do this, except for the possibility of creating a model corresponding to the corresponding type.
EDIT: if this helps, the error I received was "org.springframework.http.converter.HttpMessageNotWritableException: Failed to write JSON: Infinite recursion (StackOverflowError)" followed by a link chain trace.
source share