I'm trying to develop a little program representing link between page on a website. I want to represent each link by a relationship, and each page by a node.
For now i'm using a little data set, and it's look like :
HOME -> PAGE 1 -> PAGE 3 -> PAGE 5
     -> PAGE 2 -> PAGE 4
After inserting all my node and relation I want to traverse my graph and print data in Json to have something like :
{
  "name": "HOME",
  "children": [
    {
      "name": "PAGE 1",
      "children": [
        {
          "name": "PAGE 3",
          "children": [
            {"name": "PAGE 5"}
          ]
        },
        {
          "name": "PAGE 2",
          "children": [
            {"name": "PAGE 4"}
          ]
        }
      ]
    }
  ]
}
Is there any function doing this, or I have to write json by my own ?
Here is my code :
private static void routing( final GraphDatabaseService graphDb )
    {
        Transaction tx = graphDb.beginTx();
        Page home, p1, p2, p3, p4, p5;
        try
        {
            home = new Page(graphDb, "http://www.site.com/");
            p1 = new Page(graphDb, "http://www.site.com/page1.html");
            p2 = new Page(graphDb, "http://www.site.com/page2.html");
            p3 = new Page(graphDb, "http://www.site.com/page3.html");
            p4 = new Page(graphDb, "http://www.site.com/page4.html");
            p5 = new Page(graphDb, "http://www.site.com/page5.html");
            home.createLinkTo(p1);
            home.createLinkTo(p2);
            p1.createLinkTo(p3);
            p2.createLinkTo(p4);
            p3.createLinkTo(p5);
            tx.success();
            tx = graphDb.beginTx();
            final TraversalDescription linkTraversal = Traversal.description().depthFirst().relationships( RelationshipTypes.LINK );
            String output = "";
            for ( Node node : linkTraversal.traverse(home.getUnderlyingNode()).nodes() )
            {
                output += node.getProperty( "url" ) + "\n";
            }
            System.out.println(output);
        }
        finally
        {
            tx.finish();
        }
    }
Code of Page class
public class Page implements Serializable{
    private static final long serialVersionUID = 1L;
    static final String URL = "url";
    private final Node underlyingNode;
    private List<Page> children = null;
    public Page( final Node node )
    {
        this.underlyingNode = node;
    }
    public Page( final GraphDatabaseService graphDb, final String url )
    {
        this.underlyingNode = graphDb.createNode();
        underlyingNode.setProperty( URL, url );
        children = new ArrayList<Page>();
    }
    public Node getUnderlyingNode()
    {
        return underlyingNode;
    }
    public String getUrl()
    {
        return (String) underlyingNode.getProperty( URL );
    }
    public void createLinkTo( final Page other )
    {
        Relationship link = underlyingNode.createRelationshipTo(other.underlyingNode, RelationshipTypes.LINK );
        children.add(other);
        //link.setProperty( ANCHOR, 'Mon ancre' );
    }
    @Override
    public String toString()
    {
        return "Page [url=" + getUrl() + "]";
    }
 
     
    