Hector Barbossa
Hector Barbossa

Reputation: 5528

convert to JSON directly from DataBase resultset

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.

Upvotes: 0

Views: 1338

Answers (2)

aldrin
aldrin

Reputation: 4572

You could use a stored procedure to the format that data and return a JSON string. You would still need to work out the logic to convert those rows into a JSON structure

Upvotes: 0

Buhake Sindi
Buhake Sindi

Reputation: 89169

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.

Upvotes: 1

Related Questions