I'm collecting data from ResultSet into a list:
ResultSet resultSet = stmt.executeQuery(sql);
List<Object> res = new ArrayList<>();
while(resultSet.next()){
res.add(resultSet.getObject(1));
}
return res;
But I have issues with formatting:
I tried JSONArrays and JSONObject and what not but somehow it doesn't work. If I return just resultSet.getObject(1) for 1 row the structure looks good, but after I collect it into List or other collection it breaks. What can be solution here?
CodePudding user response:
Maybe this is not the case, but I think it is just a problem of displaying the response. I was having the same problem with my rest service, both to view it on Postman and also on browser.
On Postman just change the type of response, forcing to JSON, and the formatting was showing correctly: Force response json in Postman
To display correct formatting on the browser, I installed the "JSON Formatter" extension on Chrome.
To be safe, you can also try specifying the return in your controller's method:
@PostMapping (value = "/ .........", produces = "application / json")
public .....
but I doubt this can change anything in terms of formatting, rather at this point I would work on ObjectMapper, enabling pretty print JSON output.