title: HTTP 400 Bad request when calling Rest WebService POST method
body: <p>Please find the relevant classes and JSON request, I fail to understand what is wrong with my request, I get 400 BAD Request. The request perhaps is not even reaching the server. I dont have a clue whats missing. Appreciate your help on this</p>
  
  <p>Json request payload</p>
  
  <pre><code>{
    "campaignID": 1,
    "campaignDescription": "A Campaign #1",
    "campaignOption": "C",
    "countryID": "CI",
    "startDateTime": "02/04/2010",
    "endDateTime": "02/04/2017",
    "channelID": 3,
    "lastUpdateBy": "bbblsdcdo",
    "lastUpdateTime": "02/04/2017",
    "timestamp": "2016-11-10 23:26:10.285",
    "campaignIdCRM": null,
    "classificationCPC": null,
    "formCode": null
  }
  </code></pre>
  
  <p>Campaigns model class</p>
  
  <pre><code>package com.srisris.listload.domain;
  
  import java.util.Date;
  
  import javax.persistence.Column;
  import javax.persistence.Entity;
  import javax.persistence.Id;
  import javax.persistence.Table;
  
  import org.hibernate.annotations.Type;
  import org.joda.time.LocalDate;
  import org.springframework.format.annotation.DateTimeFormat;
  
  @Entity
  @Table(name = "Campaigns")
  public class Campaigns {
      @Id
      @Column(name = "CampaignID", nullable = false)
      private Integer campaignID;
  
      @Column(name = "CampaignDesc", nullable = false)
      private String campaignDescription;
  
      @Column(name = "CampaignOption", nullable = false)
      private String campaignOption;
  
      @Column(name = "CountryID", nullable = false)
      private String countryID;
  
      @DateTimeFormat(pattern = "dd/MM/yyyy")
      @Column(name = "StartDateTime", nullable = false)
      @Type(type = "org.jadira.usertype.dateandtime.joda.PersistentLocalDate")
      private LocalDate startDateTime;
      // private Date startDateTime;
  
      @DateTimeFormat(pattern = "dd/MM/yyyy")
      @Column(name = "EndDateTime", nullable = false)
      @Type(type = "org.jadira.usertype.dateandtime.joda.PersistentLocalDate")
      private Date endDateTime;
  
      @Column(name = "ChannelID", nullable = false)
      private Integer channelID;
  
      @Column(name = "LastUpdateBy", nullable = false)
      private String lastUpdateBy;
  
      @DateTimeFormat(pattern = "dd/MM/yyyy")
      @Column(name = "LastUpdateTime", nullable = false)
      @Type(type = "org.jadira.usertype.dateandtime.joda.PersistentLocalDate")
      private Date lastUpdateTime;
  
      private String timestamp;
  
      @Column(name = "CampaignIdCRM", nullable = true)
      private String campaignIdCRM;
  
      @Column(name = "ClassificationCPC", nullable = true)
      private String classificationCPC;
  
      @Column(name = "FormCode", nullable = true)
      private String formCode;
  
      public Campaigns() {
  
      }
  
      public Campaigns(Integer campaignID, String campaignDescription, String campaignOption, String countryID,
              LocalDate startDateTime, Date endDateTime, Integer channelID, String lastUpdateBy, Date lastUpdateTime,
              String timestamp, String campaignIDCRM, String classificationCPC, String formCode) {
          super();
          this.campaignID = campaignID;
          this.campaignDescription = campaignDescription;
          this.campaignOption = campaignOption;
          this.countryID = countryID;
          this.startDateTime = startDateTime;
          this.endDateTime = endDateTime;
          this.channelID = channelID;
          this.lastUpdateBy = lastUpdateBy;
          this.lastUpdateTime = lastUpdateTime;
          this.timestamp = timestamp;
          this.campaignIdCRM = campaignIDCRM;
          this.classificationCPC = classificationCPC;
          this.formCode = formCode;
      }
  
      public Integer getCampaignID() {
          return campaignID;
      }
  
      public void setCampaignID(Integer campaignID) {
          this.campaignID = campaignID;
      }
  
      public String getCampaignDescription() {
          return campaignDescription;
      }
  
      public void setCampaignDescription(String campaignDescription) {
          this.campaignDescription = campaignDescription;
      }
  
      public String getCampaignOption() {
          return campaignOption;
      }
  
      public void setCampaignOption(String campaignOption) {
          this.campaignOption = campaignOption;
      }
  
      public String getCountryID() {
          return countryID;
      }
  
      public void setCountryID(String countryID) {
          this.countryID = countryID;
      }
  
      public LocalDate getStartDateTime() {
          return startDateTime;
      }
  
      public void setStartDateTime(LocalDate startDateTime) {
          this.startDateTime = startDateTime;
      }
  
      public Date getEndDateTime() {
          return endDateTime;
      }
  
      public void setEndDateTime(Date endDateTime) {
          this.endDateTime = endDateTime;
      }
  
      public Integer getChannelID() {
          return channelID;
      }
  
      public void setChannelID(Integer channelID) {
          this.channelID = channelID;
      }
  
      public String getLastUpdateBy() {
          return lastUpdateBy;
      }
  
      public void setLastUpdateBy(String lastUpdateBy) {
          this.lastUpdateBy = lastUpdateBy;
      }
  
      public Date getLastUpdateTime() {
          return lastUpdateTime;
      }
  
      public void setLastUpdateTime(Date lastUpdateTime) {
          this.lastUpdateTime = lastUpdateTime;
      }
  
      public String getTimestamp() {
          return timestamp;
      }
  
      public void setTimestamp(String timestamp) {
          this.timestamp = timestamp;
      }
  
      public String getCampaignIDCRM() {
          return campaignIdCRM;
      }
  
      public void setCampaignIDCRM(String campaignIDCRM) {
          this.campaignIdCRM = campaignIDCRM;
      }
  
      public String getClassificationCPC() {
          return classificationCPC;
      }
  
      public void setClassificationCPC(String classificationCPC) {
          this.classificationCPC = classificationCPC;
      }
  
      public String getFormCode() {
          return formCode;
      }
  
      public void setFormCode(String formCode) {
          this.formCode = formCode;
      }
  
  }
  </code></pre>
  
  <p>CampaignController class</p>
  
  <pre><code>    package com.srisris.listload.controller;
  
      import java.util.List;
  
      import org.springframework.beans.factory.annotation.Autowired;
      import org.springframework.http.HttpHeaders;
      import org.springframework.http.HttpStatus;
      import org.springframework.http.MediaType;
      import org.springframework.http.ResponseEntity;
      import org.springframework.web.bind.annotation.PathVariable;
      import org.springframework.web.bind.annotation.RequestBody;
      import org.springframework.web.bind.annotation.RequestMapping;
      import org.springframework.web.bind.annotation.RequestMethod;
      import org.springframework.web.bind.annotation.RestController;
      import org.springframework.web.util.UriComponentsBuilder;
  
      import com.srisris.listload.domain.Campaigns;
      import com.srisris.listload.service.CampaignService;
  
      @RestController
      public class CampaignController {
  
          @Autowired
          CampaignService campaignService;
  
          @RequestMapping(value = "/campaign/", method = RequestMethod.GET)
          public ResponseEntity&lt;List&lt;Campaigns&gt;&gt; listAllCampaigns() {
              List&lt;Campaigns&gt; campaigns = campaignService.findAllCampaigns();
              if(campaigns.isEmpty()){
                  return new ResponseEntity&lt;List&lt;Campaigns&gt;&gt;(HttpStatus.NO_CONTENT);//You many decide to return HttpStatus.NOT_FOUND
              }
              return new ResponseEntity&lt;List&lt;Campaigns&gt;&gt;(campaigns, HttpStatus.OK);
          }
  
          @RequestMapping(value = "/campaign/{id}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
          public ResponseEntity&lt;Campaigns&gt; getCampaign(@PathVariable("id") Integer id) {
               Campaigns campaign = campaignService.findById(id);
                  if (campaign == null) {
                      System.out.println("User with id " + id + " not found");
                      return new ResponseEntity&lt;Campaigns&gt;(HttpStatus.NOT_FOUND);
                  }
                  return new ResponseEntity&lt;Campaigns&gt;(campaign, HttpStatus.OK);
          }
  
          @RequestMapping(value = "/campaign/", method = RequestMethod.POST)
          public ResponseEntity&lt;Void&gt; createCampaign(@RequestBody Campaigns campaign, UriComponentsBuilder ucBuilder) {
               if (campaignService.isCampaignExist(campaign)) {
                      System.out.println("A Campaign with ID " + campaign.getCampaignID() + " already exist");
                      return new ResponseEntity&lt;Void&gt;(HttpStatus.CONFLICT);
                  }
  
               campaignService.saveCampaign(campaign);
  
                  HttpHeaders headers = new HttpHeaders();
                  headers.setLocation(ucBuilder.path("/campaign/{id}").buildAndExpand(campaign.getCampaignID()).toUri());
                  return new ResponseEntity&lt;Void&gt;(headers, HttpStatus.CREATED);
          }
  
          @RequestMapping(value = "/campaign/{id}", method = RequestMethod.PUT)
          public ResponseEntity&lt;Campaigns&gt; updateCampaign(@PathVariable("id") long id, @RequestBody Campaigns campaign) {
              return null;
  
          }
  
          @RequestMapping(value = "/campaign/{id}", method = RequestMethod.DELETE)
          public ResponseEntity&lt;Campaigns&gt; deleteCampaign(@PathVariable("id") long id) {
              return null;
          }
  
      }
  
  
  Campaign Service Implementation Class
  
  
  package com.srisris.listload.service;
  
  import java.util.ArrayList;
  import java.util.Iterator;
  import java.util.List;
  
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.stereotype.Service;
  import org.springframework.transaction.annotation.Transactional;
  
  import com.srisris.listload.dao.CampaignDao;
  import com.srisris.listload.domain.Campaigns;
  
  @Service("campaignService")
  @Transactional
  public class CampaignServiceImpl implements CampaignService {
  
      @Autowired
      private CampaignDao campaignDao;
  
      private static List&lt;Campaigns&gt; campaigns = new ArrayList&lt;Campaigns&gt;();
  
  //  static {
  //      campaigns = populateDummyCampaigns();
  //  }
  
      @Override
      public List&lt;Campaigns&gt; findAllCampaigns() {
          return campaignDao.listAllCampaigns();
      }
  
      @Override
      public Campaigns findById(Integer id) {
  
          return campaignDao.getCampaign(id);
      }
  
      @Override
      public void saveCampaign(Campaigns campaign) {
          campaignDao.createCampaign(campaign);
  
      }
  
      @Override
      public void updateCampaign(Campaigns campaign) {
          int index = campaigns.indexOf(campaign);
          campaigns.set(index, campaign);
  
      }
  
      @Override
      public void deleteCampaign(Integer campaignID) {
          for (Iterator&lt;Campaigns&gt; iterator = campaigns.iterator(); iterator.hasNext();) {
              Campaigns campaign = iterator.next();
              if (campaign.getCampaignID() == campaignID) {
                  iterator.remove();
              }
          }
  
      }
  
  
      public Boolean isCampaignExist(Campaigns campaign) {
          return findById(campaign.getCampaignID())!=null;
      }
  
  }
  </code></pre>