Yesterday in the company platform for the development of the problems encountered, study for a day to understand, the specific situation is as follows:
When the controller returns data to the unified JSON transformation, there is a JSON infinite recursion stackoverflowerror error, that is, when JSON converts an object to JSON-formatted data, There is an infinite recursive invocation condition.
The specific situation is as follows:
In Class A, there is an attribute:list<b> B, the relationship between A and B is onetomany; in class B, there is a property A, a reference to the field ID in a, and a foreign key. Hibernate query results are normal, you can see the returned a object, there is a B parameter value, but in the JSON conversion when there is an infinite recursion situation. Personal analysis, it should be JSON in the serialization of a B property, the Class B is found, and then the Class B, and the B class has a attribute, so in order to serialize the A property, JSON has to serialize Class A, so recursive repeated, causing the problem.
Solve:
In Class B, a getter setter method annotated @jsonbackreference, in fact, I tried only in the setter method to add @jsonbackreference also enough.
Reference article:
http://my.oschina.net/u/943437/blog/145246
JSON infinite recursion Stackoverflowerror