Reputation: 147
I'm trying to build a JSON object based on the ResultSet(s) returned by our RDBMS. Each row in the ResultSet represents one object that we want to add to an array as part of the JSON. We've got the JSON schema defined in another file and I'm trying to figure out how to build the JSON based on the predefined schema.
I'm not sure if this is the best approach, to be honest. When first looking into how to approach this I was looking at JsonObjectBuilder
, but with the number of fields involved it would get pretty messy.
I'm thinking my best bet might be to create a POJO to hold the data from the ResultSet and then use Jackson ObjectMapper
to convert it into the desired JSON format.
In short:
Upvotes: 1
Views: 569
Reputation: 38300
Consider getting out of the JDBC game. MyBatis and Hibernate (probably other libs as well) do a much better job than you will ever do with a roll-your-own solution. I suggest MyBatis for simple stuff and Hibernate if you need features that are not in MyBatis.
With that in mind. create a POJO for the results of a MyBatis query then use Jackson (or gson or some other JSON library) to create the JSON.
Upvotes: 1