I am trying to serialize a tree with GSon. This is the class of my TreeNode
I want to serialize:
public class TreeNode {
private TreeNode parent;
private ArrayList<TreeNode> children;
private Object value;
//methods
}
And my GSon calls look like this:
TreeNode headNode = getHeadNode();
Gson gson = new Gson();
Type typeOfSrc = new TypeToken<TreeNode>(){}.getType();
String gsonTreeString = gson.toJson(headNode,typeOfSrc);
As soon the headNode
has at least one child, a stack overflow occurs and I don't understand why. Can someone tell me what I am doing wrong?