Json-lib appears there is a cycle in the hierarchy solution _json

Source: Internet
Author: User
Tags json tojson
Solutions

1. Set Json-lib to filter out the fields that cause loops.

Java code
Copy Code code as follows:

Jsonconfig config = new Jsonconfig ();
Config.setignoredefaultexcludes (FALSE);
Config.setcycledetectionstrategy (cycledetectionstrategy.lenient);
Config.registerjsonvalueprocessor (date.class,new datejsonvalueprocessor ("Yyyy-mm-dd")); Date Processor Register
Config.setexcludes (new string[]{//just set this array to specify which fields to filter.)
"Consignee",
"Contract",
"Coalinfo",
"Coaltype",
"Startstation",
"Balanceman",
"Endstation"
});
String tempstr = "{\" totalrecords\ ":" + total.tostring () + ", \ datas\": "+jsonserializer.tojson (List,config). ToString ( )+"}";
Out.print (TEMPSTR);
Jsonconfig config = new Jsonconfig ();
Config.setignoredefaultexcludes (FALSE);
Config.setcycledetectionstrategy (cycledetectionstrategy.lenient);
Config.registerjsonvalueprocessor (date.class,new datejsonvalueprocessor ("Yyyy-mm-dd")); Date Processor Register
Config.setexcludes (new string[]{//just set this array to specify which fields to filter.) "Consignee", "contract", "Coalinfo", "Coaltype", "Startstation", "Balanceman", "endstation"}); String tempstr = "{\" totalrecords\ ":" + total.tostring () + ", \ datas\": "+jsonserializer.tojson (List,config). ToString ( )+"}"; Out.print (TEMPSTR);

2. Set the Json-lib Setcycledetectionstrategy property to handle the loop itself, but the data is too complex to cause data overflow or inefficiency.
Java code
[Code]
Jsonconfig config = new Jsonconfig ();
Config.setignoredefaultexcludes (FALSE);
Config.setcycledetectionstrategy (cycledetectionstrategy.lenient);
Config.registerjsonvalueprocessor (date.class,new datejsonvalueprocessor ("Yyyy-mm-dd")); Date Processor Register
String tempstr = "{\" totalrecords\ ":" + total.tostring () + ", \ datas\": "+jsonserializer.tojson (List,config). ToString ( )+"}";
Out.print (TEMPSTR);

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.