package com.list;
import java.util.List;
public class Group {
private String name;
private List<User> userList;
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @param name
* the name to set
*/
public void setName(String name) {
this.name = name;
}
/**
* @return the userList
*/
public List<User> getUserList() {
return userList;
}
/**
* @param userList
* the userList to set
*/
public void setUserList(List<User> userList) {
this.userList = userList;
}
}package com.list;
public class User {
public String name;
public Group group;
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @param name the name to set
*/
public void setName(String name) {
this.name = name;
}
/**
* @return the group
*/
public Group getGroup() {
return group;
}
/**
* @param group the group to set
*/
public void setGroup(Group group) {
this.group = group;
}
}以上二个类是嵌套关系,在转json前,user 或者 group 已经被其它实例引用,这个转json就会循环直到convertDepth变为0.有什么更好的办法阻止这种循环吗
JFinalJson json = new JFinalJson();
json.setConvertDepth(2);
String jsonString = json.toJson(...);