title: How to return a list of object as Json in Spring MVC
body: <p>I'm trying to get a list of objects to render on a Spring 3 MVC app and would like to do this via Ajax.</p>
  
  <p>So in my Spring class I have:</p>
  
  <pre><code>@RequestMapping(value = "/viewSearchEnquiriesAjax", method = RequestMethod.GET, headers = "Accept=application/json")
  public @ResponseBody List&lt;Enquiry&gt; getEnquiriesBySearchAjax(@RequestParam String name) {
      Search search =  new Search();
      search.setFirstName(name);
      return searchEnquiries(search);
  }
  </code></pre>
  
  <p>But I get a 500 (Internal Server Error) when this is run.  This manifests itself when I'm debugging in the browser as <code>'GET http://localhost:8080/SpringMVC/viewSearchEnquiriesAjax?name=peter 500 (Internal Server Error)'</code></p>
  
  <p>I can successfully return a single object with no error.  Can the Spring Json mapper(Jackson) convert correctly?  Am I missing something fundamental?</p>
  
  <p>My javascript is as follows:</p>
  
  <pre><code>function doAjaxPost() {
  // get the form values
  var firstName = $('#firstName').val();
  $.getJSON("/SpringMVC/viewSearchEnquiriesAjax", { name: firstName }, function(result) {
      alert("Success");
   });
  
  }
  </code></pre>
  
  <p>My Enquiry object is an Entity:</p>
  
  <pre><code>@Entity
  @Table(name = "enquiries")
  public class Enquiry implements java.io.Serializable{
  
      private static final long serialVersionUID = -5093725544297637792L;
  
      protected Long id;
      protected Date created = new Date();
      ...
      ...
  
      public Enquiry() {
      }
  
      @Id
      @GeneratedValue(strategy = GenerationType.AUTO)
      @Column(name = "id", unique = true, nullable = false)
      public Long getId() {
          return this.id;
      }
  
      public void setId(Long id) {
          this.id = id;
      }
     ...
     ...
  </code></pre>