title: Construct JSON Object based on Query Result List
body: <p>Trying to figure out a solution for a problem I am facing, but cannot find any material online so far to help me.</p>
  
  <p>Essentially what I have is a method in a rest controller that passes a query string to my Hibernate DAO and gets in return data requested.</p>
  
  <p>e.g.</p>
  
  <pre><code>@RequestMapping("/submitQuery")
      public Object submitQuery() {
  // example of a query string, note this is dynamic and thus never hardcoded
          String query = "SELECT C.amount, C.transactionDate, R.amount, R.transactionDate FROM CAR C, RFT R";
  
          return  DAO.submitQuery(query);
      }
  </code></pre>
  
  <p>DAO:</p>
  
  <pre><code>public List&lt;T&gt; submitQuery(String query) {
          Query q = getSession().createQuery(query);
          return q.list();
      }
  </code></pre>
  
  <p>This query string will be dynamic so the option of creating a entity and attaching it against query is not an option.</p>
  
  <p>The above method will return data in following format:</p>
  
  <pre><code>[
      [
          -4890.38,
          1451826000000,
          25.04,
          1421499600000
      ],
      [
          -660,
          1413205200000,
          25.04,
          1421499600000
      ],
      [
          -10768.53,
          1423054800000,
          25.04,
          1421499600000
      ]
  ]
  </code></pre>
  
  <p>So no headers and on top of that dates have been converted into digits.
  What i want to achieve is have the method return the results in following format:</p>
  
  <pre><code>[
      [
          "amountc" : -4890.38,
          "datec" : "01-03-2014",
          "amountr" : 25.04,
          "dater" : "01-03-2014"
      ],
      [
          "amountc" : -660,
          "datec" : "03-02-2014",
          "amountr" : 25.04,
          "dater" : "03-02-2014"
      ],
      [
          "amountc" : -10768.53,
          "datec" : "01-02-2014",
          "amountr" : 25.04,
          "dater" : "01-02-2014"
      ]
  ]
  </code></pre>
  
  <p>Any advice/assistance would be appreciated.</p>
  
  <p><strong>NOTE: Cannot use DTOs or Entities as the Query String is dynamic and changes. Query string i have there is just as example.</strong></p>