title: Spring MVC + jQuery Datatables + JSON Response
body: <p>I have a Spring MVC application using jQuery Datatables to render the data.
  Here are my classes and javascript code</p>
  
  <p><strong>Employee.java</strong></p>
  
  <pre><code>public class Employee {
      private int empId ;
      private String firstName;
      private String lastName ;
  
      // getters and setters
  }
  </code></pre>
  
  <p><strong>EmployeeResponse.java</strong></p>
  
  <pre><code>public class EmployeeResponse {
  
      private List&lt;Employee&gt; empList ; 
  
      // getters and setters
  
  }
  </code></pre>
  
  <p><strong>EmployeeController.java</strong></p>
  
  <pre><code>@Controller
  @RequestMapping("/admin")
  public class EmployeeController {
  
      @RequestMapping(value = "/get-all-employee", method = RequestMethod.POST, consumes = { MediaType.APPLICATION_JSON_VALUE })
      @ResponseBody
      public EmployeeResponse getAllEmployee(HttpServletRequest request) {
          EmployeeResponse response = new EmployeeResponse();
          try {
  
              response = getAllEmployeeList(); // returns response object
  
          } catch (Exception e) {
              logger.error("DCConsoleController::createNewStream exception: " + com.priceline.utils.StringUtils.getStackTrace(e));
              return null;
          }
          return response ; 
      }
  }
  </code></pre>
  
  <p><strong>emp.jsp</strong></p>
  
  <pre><code>&lt;div class="row"&gt;
      &lt;table id="ldapStreamTable" class="table"&gt;
          &lt;thead&gt;
              &lt;tr&gt;
                  &lt;th&gt;Emp Id&lt;/th&gt;
                  &lt;th&gt;First Name&lt;/th&gt;
                  &lt;th&gt;Last Name&lt;/th&gt;
              &lt;/tr&gt;
          &lt;/thead&gt;
      &lt;/table&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p><strong>emp.js</strong></p>
  
  <pre><code>$(document).ready(function() {
      var table = $('#appTable').DataTable( {
          "sDom" : domSetting,
          "oLanguage" : {
              "sLengthMenu" : "_MENU_ records per page",
              "sSearch" : "&lt;span class='add-on'&gt;&lt;i class='icon-search'&gt;&lt;/i&gt;&lt;/span&gt;Search Application:",
              "sZeroRecords" : "No matching records found",
          },
          "iDisplayLength" : 10,
          "aLengthMenu" : [
                  [ 5, 10, 20, 25, 50, -1 ],
                  [ 5, 10, 20, 25, 50, "All" ] ],
          "aaSorting" : [ [ 0, 'asc' ] ],
          'sAjaxSource': '{context}/admin/get-all-employee',
          [Pending here]
      });
  });
  </code></pre>
  
  <p>What should I do to get the response as json and apply/use render methods for each column to render the data into the table?</p>
  
  <p>[Note: looks like I can't use aoColumns' with mData for each column because my json response is list of employee objects]</p>
  
  <p>Update - 1: Sample json below</p>
  
  <pre><code>{"empList":[{"empId":3,"firstName":"Kiran","lastName":"Kumar"},{"empId":1,"firstName":"John","lastName":"Smith"},{"empId":0,"firstName":"Sachin","lastName":"Kumar"}]}
  </code></pre>