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:
- How would I dynamically create a JSON object based on a schema and populated with the results of a database query?
- If that's not feasible or efficient, what would be a better/the best way to dynamically create a JSON object populated with the results of a database query and adhering to a specific format?