1

I have seen this error solved with many questions in the past with 2 objects which reference each other, but I can't seem to solve it using these techniques referenced (using this line, mainly):

@JsonIgnoreProperties("day")

My issue is that I have 3 objects which have something of a love triangle going on. Here is (some) of the error:

com.fasterxml.jackson.databind.JsonMappingException: Infinite recursion (StackOverflowError) 
(through reference chain: java.util.ArrayList[0]->DataObjects.EmployeeShiftAllocation["shift"]->
DataObjects.Shift["day"]->DataObjects.Day["employeeShiftAllocations"]->
java.util.ArrayList[0]->DataObjects.EmployeeShiftAllocation["shift"]->DataObjects.Shift["day"]->......... etc

So I have an object EmployeeShiftAllocation, which references a Shift, which references a Day, which has a list of EmployeeShiftAllocations.

I applied the aforementioned suggested solution, but it did not solve the problem. I placed that statement before the declaration / initialization of the 3 aforementioned objects.

Any help is appreciated.

1

2 Answers 2

2

you can try using @JsonIdentityInfo which will create a reference for hibernate in the second level of serialization which will break the cycle

@Entity
@JsonIdentityInfo(generator=ObjectIdGenerators.UUIDGenerator.class, property="@id")
Sign up to request clarification or add additional context in comments.

4 Comments

Thanks for your answer. What is the purpose of the @Entity tag? I see it's likely used with a JPA, but I've never used JPAs before. Could you recommend a way forward using your answer with a JPA?
@Entity is used with jpa , it specify your model to be an entity and mapped by a table in the database, the annotations I shared should be placed above the name of your class you are facing the problem serializing
So I added EclipseLink JAR to my buildpath to allow use of JPA stuff, but my @Entity tag is still not being recognised. "Entity cannot be resolved to a type".
I found I was missing a JAR. I still have the same problem with your answer sadly Amer.
1

Managed to fix the issue by using

@JsonIgnore

From the EclipseLink JPA, on the Shift object. This caused the recursive loop to break, solving the issue.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.