title: ajax post call causes 400 (Bad Request) on sending array to spring rest controller
body: <p>I have <code>OneToMany</code> mapping as </p>
  
  <pre><code>@Entity
  public class Foo implements Serializable {
  
      private static final long serialVersionUID = 1L;
  
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      private long fooId;
      private String fooName;     
  
      @OneToMany(mappedBy = "foo", cascade = CascadeType.ALL)
      private Set&lt;Bar&gt; bars = new HashSet&lt;Bar&gt;();
  
      // getters and setters go here
  }
  </code></pre>
  
  <p>and </p>
  
  <pre><code>@Entity
  public class Bar implements Serializable {     
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      private long barId;
      private String barTitle;
      private static final long serialVersionUID = 1L;
      @ManyToOne
      @JoinColumn(name = "fooId")
      private Foo foo;
      // getters and setters go here
  }
  </code></pre>
  
  <p>I've created a FooRestController to save data using ajax </p>
  
  <pre><code>@RequestMapping(value = "/foo/", headers="Accept=*/*", consumes="application/json", method = RequestMethod.POST)
      public ResponseEntity&lt;Void&gt; create(@RequestBody Foo foo) {           
          fooService.saveFoo(foo);
          Set&lt;Bar&gt; bars = foo.getBars();      
  
          for (Bar bar : bars) {
              barService.savebar(bar);            
          }       
  
          return new ResponseEntity&lt;Void&gt;(HttpStatus.CREATED);
      }
  </code></pre>
  
  <p>my ajax POST request is </p>
  
  <pre><code>var barArray = [];
  bar[0] = "Bar1";
  bar[1] = "Bar2";
  $.ajax({
      contentType : 'application/json',
      crossDomain: true,
      type: 'POST',
      url: '/foo/',
      dataType : 'json',
      data : JSON.stringify({        
          'fooName' : 'A',
          'bars' : barArray // this line here causes error 
  })
  </code></pre>
  
  <p>at this point I'm getting error as </p>
  
  <pre><code>POST http://localhost:8080/name/foo/ 400 (Bad Request)
  </code></pre>
  
  <p>any suggestions for saving barArray of foo.</p>
  
  <h2>Note</h2>
  
  <p>when ever I send data using Postman as </p>
  
  <pre><code>{
  
      "fooName": "A",       
     "bars" : [
           {
              "barTitle" : "a"                
           }           
         ]
  }
  </code></pre>
  
  <p>data is inserted and a new foo is created in db.</p>