title: Spring JPA Custom Query to return JSON
body: <p>I am using Spring hibernate with JPA Repository to return the values as JSON. It works fine for all default cases. I am having a problem with custom query in my CrudRepository to return aggregated values as JSON.</p>
  
  <p>CrudRepository</p>
  
  <pre><code>@Repository
  public interface ExpenseRepository extends CrudRepository&lt;Expense, Integer&gt;{
      @Query("SELECT min(dtDate) as dtDate ,Max(dtDate) as dtDate FROM Expense")
      Iterable&lt;Expense&gt; getAvlRptDates();
  }
  </code></pre>
  
  <p>NOTE: I have tried with and without Alias, List etc as well.</p>
  
  <p>Controller</p>
  
  <pre><code>@ResponseBody
  @RequestMapping(value="/getAvlExpMonthYear",method=RequestMethod.GET)
  public Iterable&lt;Expense&gt; getAvlRptDates(){
      //String test = testRepo.findAll().toString();
      return expRepo.getAvlRptDates();
  }
  </code></pre>
  
  <p>I tried with List as well. I know that converting to JSON with custom code or additional dto classes.</p>
  
  <p>Please let me know if there any easy way without creating additional domain class or dto classes just for two fields.</p>