天天看点

解决SpringBoot中FastJson循环引用$.ref的问题

问题背景

再使用SpringBoot+FastJson的时候,如果json里面的list,包含相同内容,会显示为

$.ref[x]

或者

$.row[x].xxx[x]

,所以需要在FastJson里面设置一下。

解决SpringBoot中FastJson循环引用$.ref的问题

解决方法

解决SpringBoot中FastJson循环引用$.ref的问题

1。FastJson的.java配置增加以下项

//禁用循环引用$ref.xxx[x]
fastConverter.setFeatures(SerializerFeature.DisableCircularReferenceDetect);
           

2。如果是代码显式转换,需要

//传入对象进行转换
JSON.toJSONString(object, SerializerFeature.DisableCircularReferenceDetect);