What I'm looking for seems pretty straight forward to me, but my googles have failed.
I want a method that allows me to run any query and get the results in json format.
The trick is I don't want the results to need java objects as part of the process (DTOs, VOs, etc).
Any quick/easy/clean ways of doing this?
I think you have two options:
Map
instance.I accepted DominicEU's answer because it provided me with what I needed to get things working. Pheonix's answer in the link was good, but still lacked some details. Below shows the pom and a working example... (you'll probably want to rework the connection stuff for real implementation):
Java Code:
Maven pom:
Very Interesting question. I am not sure is there any library that directly does this. But we have couple of options in doing that.
We can have DataAccessLayer that can be generic fetch the data. For converting the entity to Json object, we need provide the logic in the specific entity class(Separate JSON generation class).
The way I usually do this along with my colleagues is that we create harness or controller class, that usually points to a SQL connection. The job of the harness is to pull your information from the SQL db into your json file. However, you will need to create a stored procedure and you will need to call that stored procedure in your SQL Connection class.
Jackson has some pretty nice ways of doing it. There's some examples in this answer that should work wonders for you.
Alternatively, if Jackson isn't available to you, you could check out this