title: A POST request is giving me a 400 Bad Request
body: <p>I use angularjs in my project. I am getting a 400 bad request whenever a POST request is made using AttachmentsFactory. POST function of all other factories are working properly. Here's the 
  <strong>controller function</strong>
  `</p>
  
  <pre><code>$scope.updateAttachment = function(attachment){
          console.log(JSON.stringify(attachment));
          var response = AttachmentsFactory.update(attachment); //**here's the problem**
          response.$promise.then(function(data){
              attachment.edit = false;
          })
          /*$http.post("/rest/attachments", attachment).success(function(data){
              //Callback function here.
              //"data" is the response from the server.
          });*/   
      }
  </code></pre>
  
  <p>`
  and the Factory <strong>AttachmentsFactory</strong></p>
  
  <pre><code>services.factory('AttachmentsFactory', function ($resource) {
     return $resource('/rest/:eventId/attachments/:fileId', {}, {
         query: { method: 'GET', isArray: true },
         remove: {method: 'DELETE'},
         update: {method: 'POST', headers:{'Content-Type':'application/json'}}
     })
  });
  </code></pre>
  
  <p>The request is not reaching the server. The object passed as argument is valid : 
  <code>{"name":"ccccc",
    "description":"cccc cccc cccc cccc cccc cccc cccc",
    "fileId":"55144430d18567d9335a94c7",
    "thumbNailId":null,
    "extenstion":"jpg",
    "visibleToPublic":false,
    "edit":true,
    "$$hashKey":"object:565"
   }</code></p>
  
  <p>The server function that receives the rest is as follows</p>
  
  <pre><code>@BodyParser.Of(BodyParser.Json.class)
  public Result updateEventAttachment(String eventId) {
      try {
          logger.warn("HERE HERE HERE HERE HERE HERE HERE HERE HERE HERE HERE HERE HERE HERE HERE HERE HERE ");
          JsonNode json = request().body().asJson();
          Attachment attachment = Json.fromJson(json, Attachment.class);
          logger.debug("Update Request received eventId ={}, fileid{}", eventId, attachment.getFileId());
          Event event = eventService.getEvent(eventId);
          Set&lt;Attachment&gt; attachments = event.getAttachments();
          logger.debug(" Size of attachments = {}", attachments.size());
          attachments.remove(attachment);
          attachments.add(attachment);
          eventService.updateEvent(event);
      } catch (Exception e) {
          logger.warn(" method = deleteEventAttachment exception={}",
                  e.toString());
          e.printStackTrace();
      }
      return ok();
  }
  </code></pre>
  
  <p>I added the field <code>headers:{'Content-Type':'application/json'}</code> to the POST method, its not helping. I also tried using $http instead on $resource. Still the same. Tried replacing POST with PUT, still the same.
  The GET and DELETE functions of AttachmentsFactory are working properly.
  Can anyone help me figure out what I am doing wrong? 
  Have been stuck with this for more than a day.</p>