在处理有级联关系的pojo的时候json会报net.sf.json.JSONException: There is a cycle in the hierarchy的错误,使得json会层层循环抛出异常,解决该问题可通过配置JsonConfig来解决,代码如下:
JsonConfig jsonConfig = new JsonConfig();
jsonConfig.setCycleDetectionStrategy(CycleDetectionStrategy.LENIENT);
String[] excludes = { "farms" };//-->设置属性的排除列表,也就是说指出不需要序列化的属性
jsonConfig.setExcludes(excludes);
JSONArray json = JSONArray.fromObject(lstShelf, jsonConfig);
response = json.toString();