I have data from the DB as follows.
ID PARENT ID NAME
5344 (null) Qwest Washington
83688 5344 Anderson
83690 83688 Anderson_Const
83712 83688 Larson_Cable
83726 83712 SEAIR
83714 83688 Larson_Const
83748 83714 SECN2
83750 83714 SECN3
83692 5344 Butler
83694 83692 Cini_Const
83696 83692 Cini_Loop
83834 83696 TANW1
83836 83696 TANW2
83702 83692 Flores
83704 83702 Flores_Design
83730 83702 SEBG2
83732 83702 SEBG4
83734 83702 SEBG5
Data given above will change for each user. i want to write generic java method which construct tree and return output as jsonString like below,
{id:'0',text:'Org Node',expanded: true, children:
[
{ id:'Org1', text: "node1", leaf: true },
{id:'Org2', text: "node2", expanded: true, children: [
{ id:'Org21', text: "node2-1", leaf: true },
{ id:'Org22', text: "node2-2", leaf: true }
]
},
{id:'Org3', text: "node3", leaf:true },
{id:'Org4', text: "node4", children: [
{ id:'Org41', text: "node4-1", leaf: true },
{ id:'Org42', text: "node4-2", leaf: true }
]
},
{id:'Org5', text: "node-5", leaf: true }
]
}
Please give me a generic concept to make tree in JAVA.