I am working on a project using JPA (EclipseLink 2.5.2) and Jersey 2.27 running on Tomcat 8 under Java 8. Currently I retrieve results using mapped entities and also some simple lists (distinct values, key-value pairs). I have implemented server-side paging, filtering and sorting. Now I'm trying to add the ability to dynamically aggregate data sets.
I've searched on SO and other sites for the best way to serialize a list of Tuples returned from my criteria builder query. So far I haven't found anything that answers my question. I can think of three ways to do it barring some good pointers from here:
- Use reflection to create the appropriate object and supply it in my query
- Run through the results one at a time and write out my own JSON for each element to a StringBuffer
ArrayList<HashMap<String, Object>>
where the HashMap is built using the alias and matching result then added to the list, list is serialized as normal
So if there is no "easy" way to serialize a list of tuples, which method above makes the most sense? Option 3 definitely works, but feels like a kludge to me.