}
protected void encodeNode(FacesContext context, Mindmap map, MindmapNode node, String nodeKey) throws IOException {
ResponseWriter writer = context.getResponseWriter();
List<MindmapNode> children = node.getChildren();
MindmapNode parent = node.getParent();
writer.write("{");
encodeNodeConfig(context, map, node, nodeKey);
if(parent != null) {
String parentNodeKey = (nodeKey.indexOf("_") != -1) ? nodeKey.substring(0, nodeKey.lastIndexOf("_")) : "root";
writer.write(",\"parent\":{");
encodeNodeConfig(context, map, parent, parentNodeKey);
writer.write("}");
}
if(!children.isEmpty()) {
int size = children.size();
writer.write(",\"children\":[");
for(int i = 0; i < size; i++) {
String childKey = (nodeKey.equals("root")) ? String.valueOf(i) : nodeKey + "_" + i;
MindmapNode child = children.get(i);
encodeNode(context, map, child, childKey);
if(i != (size - 1)) {
writer.write(",");
}