Open fxleyu opened 4 months ago
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.serializer.SerializerFeature; import com.google.common.collect.Lists; public class JsonTest { @Test public void test() { Map<String, String> strMap = new HashMap<>(); strMap.put("1", "one"); List<Map<String, String>> list = Lists.newArrayList(strMap, strMap, strMap, strMap); System.out.println(JSON.toJSONString(list)); System.out.println(JSON.toJSONString(list, SerializerFeature.DisableCircularReferenceDetect)); } }
打印结果
[{"1":"one"},{"$ref":"$[0]"},{"$ref":"$[0]"},{"$ref":"$[0]"}] [{"1":"one"},{"1":"one"},{"1":"one"},{"1":"one"}]
打印结果