$ref circular reference appears in fastjson

Reference: https://www.cnblogs.com/taoxw/p/16589878.html

Problem Description:

When using fastjson to serialize an object into a string, sometimes $ref occurs , which is called a circular reference ( CircularReference ). As shown below:

 

Why does $ref appear

. This is because there is a relational reference between objects.

Solution

Use the serialization feature class ( SerializerFeature ), the code is as follows

response.setCharacterEncoding("utf-8");

response.setContentType("application/json; charset=utf-8");

String jsonString = JSON.toJSONString(data, SerializerFeature.DisableCircularReferenceDetect, SerializerFeature.PrettyFormat);

Guess you like

Origin blog.csdn.net/banzhengyu/article/details/130021715