title: Serializing List<javax.persistence.Tuple> to JSON
body: <p>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 <strong>dynamically</strong> aggregate data sets.</p>
  
  <p>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:</p>
  
  <ol>
  <li>Use reflection to create the appropriate object and supply it in my query</li>
  <li>Run through the results one at a time and write out my own JSON for each element to a StringBuffer</li>
  <li><code>ArrayList&lt;HashMap&lt;String, Object&gt;&gt;</code> where the HashMap is built using the alias and matching result then added to the list, list is serialized as normal</li>
  </ol>
  
  <p>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.</p>