title: Convert List<Object[]> to JSON
body: <p><strong>Hi guys!</strong></p>
  
  <p>Can someone helps me, how to convert my HQL query results to JSON with list of objects and get it with rest service.</p>
  
  <p><strong>Here is my service method which returns qyery result list:</strong> </p>
  
  <pre><code>   @Override
      public List&lt;Object[]&gt; getAllDepartments() {
          List&lt;Object[]&gt; list;
          Query query =  entityManager.createQuery("SELECT dp.name, avg (wr.salary) FROM Worker wr join wr.department dp GROUP BY dp.name");
          list =  query.getResultList();
          return list;
      }
  </code></pre>
  
  <p><strong>And my Spring RESTfull Controller:</strong></p>
  
  <pre><code>@RequestMapping(value = "/all", method = RequestMethod.GET)
  @ResponseBody
  public JsonNode getAllDeps() {
      List&lt;Object[]&gt; list  = departmentService.getAllDepartments();
      ObjectMapper objectMapper = new ObjectMapper();
      Map&lt;String, Integer&gt; resultMap = new HashMap&lt;String, Integer&gt;(list.size());
      for (Object[] result : list)
          resultMap.put((String)result[0], ((Double)result[1]).intValue() );
      final JsonNode json = objectMapper.valueToTree(resultMap);
      return json;
  }
  </code></pre>
  
  <p>Now my service responce me json with data in thats look :
  {"Security":1500,"Economical":1850,"IT":2000}</p>
  
  <p>But i need in that(list of objects):</p>
  
  <p>[{name:"Security",salary:"1500"},{name:"Economical",salary:1850},{name:"IT",salary:2000}]</p>
  
  <p>Thanks for help.</p>