Reason: When JSON is processing data, the same data appears, and JSON automatically replaces the data of the same node with a reference.
Solution:
String jsonString = JSON.toJSONString(params, SerializerFeature.DisableCircularReferenceDetect);
SerializerFeature.DisableCircularReferenceDetect: Eliminate the problem of circular references to the same object
Extensions:
name | meaning |
QuoteFieldNames | Whether to use double quotes when outputting the key, the default is true |
UseSingleQuotes | Use single quotes instead of double quotes, defaults to false |
WriteMapNullValue | Whether to output fields with null values, the default is false |
WriteEnumUsingToString | Enum outputs name() or original, the default is false int features=SerializerFeature.config(JSON.DEFAULT_GENERATE_FEATURE, SerializerFeature.WriteEnumUsingName, false) |
UseISO8601DateFormat | Date is output in ISO8601 format, the default is false |
WriteNullListAsEmpty | If the List field is null, the output is [] instead of null. |
WriteNullStringAsEmpty | If the character type field is null, the output is "", not null. |
WriteNullNumberAsZero | If the numeric field is null, the output is 0 instead of null. |
WriteNullBooleanAsFalse | If the Boolean field is null, the output is false, not null. |
SkipTransientField | If it is true, the Field corresponding to the Get method in the class is transient and will be ignored during serialization. Default is true |
SortField | Output after sorting by field name. Default is false |
WriteTabAsSpecial | Use \t to escape the output, the default is false |
PrettyFormat | Whether the result is formatted, the default is false |
WriteClassName | Write type information during serialization, default is false. Deserialization is required |
DisableCircularReferenceDetect | Eliminate the problem of circular references to the same object. The default is false. [ Circular references A a = new A(); 引用是通过"$ref"来表示的 引用描述
|
WriteSlashAsSpecial | 对斜杠’/’进行转义 |
BrowserCompatible | 将中文都会序列化为\uXXXX格式,字节数会多一些,但是能兼容IE 6,默认为false |
WriteDateUseDateFormat | 全局修改日期格式,默认为false。 JSON.DEFFAULT_DATE_FORMAT = “yyyy-MM-dd”; JSON.toJSONString(obj, SerializerFeature.WriteDateUseDateFormat); |
DisableCheckSpecialChar | 一个对象的字符串属性中如果有特殊字符如双引号,将会在转成json时带有反斜杠转移符。如果不需要转义,可以使用这个属性。默认为false |
NotWriteRootClassName | 含义 |
BeanToArray | 将对象转为array输出 |