Solution
1. Set JSON-LIB to filter out fields that cause loops.
Java code
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 and 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 and 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 setCycleDetectionStrategy attribute of JSON-LIB to let it handle the cycle by itself, which saves trouble. However, if the data is too complex, it will cause data overflow or low efficiency.
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);