1 2 4 5
1 2 4 5
1 2 4 5
1 2 4 5
1 2 4 6
1 3 4 6
1 3 4 6
Consider the above as a DB result set . Here One root is there that is 1 ,which has two children 2 and 3. Both 2 and 3 have 4 as their child. 4 has two children 5 and 6.
Now to convert the same tree structure to JSON I am populating a bean in java and then converting the bean to a JSON String. I am interested to whether it is possible to achieve the same directly from Database result to JSON.
Directly (without writing an data converter), no. You can write a converter that will take the bean and convert the data structure into a JSON String. One such library that does that is Google GSON. Other than that, I’m afraid not.