I have query result like this :
| DEPT_NAME | DEPT_R_IDX | DEPT_IDX | DEPT_LEVEL |
|---|---|---|---|
| root | 0 | 1 | 0 |
| dept_0 | 1 | 2 | 1 |
| dept_1 | 1 | 3 | 1 |
| dept_1_0 | 3 | 4 | 2 |
| dept_1_1 | 3 | 5 | 2 |
| dept_2 | 1 | 6 | 1 |
| dept_2_0 | 6 | 7 | 2 |
| dept_2_0_1 | 7 | 8 | 3 |
- DEPT_IDX is PRIMARY KEY, DEPT_LEVEL is TREE DEPTH, DEPT_R_IDX is parent's DEPT_IDX
I stored this data in Java's List.
List<HashMap<String, String>> DEPT_LIST;
I want convert this List to Json like this :
[
{
"title": "root",
"key": "1",
"expanded": true,
"folder": true,
"children": [
{
"key": "2",
"title": "dept_0",
"expanded": true,
"folder": true
},
{
"key": "3",
"title": "dept_1",
"expanded": true,
"folder": true,
"children": [
{
"key": "4",
"title": "dept_1_0",
"expanded": true,
"folder": true
},
{
"key": "5",
"title": "dept_1_1",
"expanded": true,
"folder": true
}
]
},
{
"key": "6",
"title": "dept_2",
"expanded": true,
"folder": true,
"children": [
{
"key": "7",
"title": "dept_2_0",
"expanded": true,
"folder": true,
"children": [
{
"key": "8",
"title": "dept_2_1",
"expanded": true,
"folder": true
}
]
}
]
}
]
}
]
result tree using this json data(using fancytree)

i tried this in browser side, but it's too low performance to make json structure
Instead of storing your data in a
List<HashMap<String, String>>, store them in aList<Node>where classNodeis something like this:Then use Jackson or Gson to generate the corresponding Json.