JSON infinite recursion Stackoverflowerror

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.