title: Spring POST receives object with null values
body: <p>I have an AngularJS web application that looks like it is correctly sending JSON to the Tomcat server, but the server receives null values. <a href="https://stackoverflow.com/questions/38935912/requestbody-is-getting-null-values">This question</a> didn't help because my property names are already lowercase, and <a href="https://stackoverflow.com/questions/43373421/spring-rest-json-post-null-values">this question</a> didn't help because I've already got the <code>@RequestBody</code> notation. <strong>Edit: as pointed out in the comments, I don't actually have this notation. I was reading it wrong.</strong></p>
  
  <p>Here is the server method in question:</p>
  
  <pre><code>@PostMapping(path="/kind/add")
  public @ResponseBody String addNewKind(Kind kind) throws Exception {
      if (kind.getName() == null) {
          throw new Exception("Name not found.");
      }
      kindRepository.save(kind);
      return "Saved";
  }
  </code></pre>
  
  <p>Here is the Kind object it expects to receive:</p>
  
  <pre><code>@Entity
  public class Kind {
  
      @Id
      @GeneratedValue(strategy=GenerationType.AUTO)
      private int id;
      private String name;
      @OneToMany(mappedBy="kind")
      private Set&lt;Card&gt; cards;
  
      public int getId() {
          return id;
      }
  
      public void setId(int id) {
          this.id = id;
      }
  
      public String getName() {
          return name;
      }
  
      public void setName(String name) {
          this.name = name;
      }
  
      public Set&lt;Card&gt; getCards() {
          return cards;
      }
  
      public void setCards(Set&lt;Card&gt; cards) {
          this.cards = cards;
      }
  }
  </code></pre>
  
  <p>Here is the method that makes the request:</p>
  
  <pre class="lang-js prettyprint-override"><code>var uri = 'http://localhost:8080/catalog/api/kind/';
  
  function create(name) {
      var deferred = $q.defer();
      var data = {
          'name': name
      };
      $http({
          method: 'POST',
          url: uri + 'add',
          data: angular.toJson(data),
          headers: {
              'Content-Type': 'application/json; charset=UTF-8'
          }
      }).then(function(response) {
          deferred.resolve(response.data);
      }).catch(function(error) {
          console.error('Error while adding kind');
          deferred.reject(error);
      });
      return deferred.promise;
  }
  </code></pre>
  
  <p>This is the JSON sent to the server:</p>
  
  <pre><code>{"name":"Something"}
  </code></pre>
  
  <p><strong>N.B.</strong> I assumed that I can get away without sending <code>id</code> or <code>cards</code> parameters, since <code>id</code> is auto-generated and <code>cards</code> can be empty; however, I get the same null results when sending the following JSON:</p>
  
  <pre><code>{"id":0,"name":"Something","cards":[]}
  </code></pre>
  
  <p>These are the request headers:</p>
  
  <pre class="lang-none prettyprint-override"><code>Accept:           application/json, text/plain, */*
  Accept-Encoding:  gzip, deflate
  Accept-Language:  en-US,en;q=0.5
  Connection:       keep-alive
  Content-Length:   20
  Content-Type:     application/json; charset=UTF-8
  Cookie:            __distillery=08c4ef1_752470a4-…ID=lr9remoqoi0ht13v1urq5lq8r7
  Host:             localhost:8080
  Referer:          http://localhost:8080/catalog/
  User-Agent:       Mozilla/5.0 (Windows NT 10.0; …) Gecko/20100101 Firefox/57.0
  </code></pre>
  
  <p>And this is what the server receives when I view the <code>kind</code> object argument in debug mode:</p>
  
  <pre><code>kind= Kind
      cards= null
      id= 0
      name= null
  </code></pre>