title: Cannot deserialize instance of `java.lang.Long` out of START_OBJECT token; on Spring boot post
body: <p>I want to post a new Game to my spring boot backend from my angular application.
  I do this through an post from angular. This game has a relationship with my user entity in spring boot JPA. But when I do my post I get an 400 error code in the console which says:</p>
  <blockquote>
  <p>&quot;MethodArgumentNotValidException&quot;,&quot;fieldErrors&quot;:[{&quot;field&quot;:&quot;user&quot;,&quot;errorCode&quot;:&quot;NotNull&quot;}]}</p>
  </blockquote>
  <p>This was the data from my post:</p>
  <pre><code>{category: &quot;sport&quot;, sessieId: 20004, userID: 10004, score: null}
  </code></pre>
  <p>My game <code>controller</code>:</p>
  <pre><code>@CrossOrigin(origins = &quot;*&quot;, allowedHeaders = &quot;*&quot;)
  @RestController
  @RequestMapping(value = &quot;/api/games&quot;, produces = MediaType.APPLICATION_JSON_VALUE)
  public class GameController {
  
  @PostMapping
      @ResponseStatus(HttpStatus.CREATED)
      public Long createGame(@RequestBody @Valid final GameDTO gameDTO) {
          return gameService.create(gameDTO);
      }
   // more methods for http
  }
  </code></pre>
  <p>my Game <code>domain</code>:</p>
  <pre><code>@Entity
  public class Game {
  
      @Id
      @Column(nullable = false, updatable = false)
      @SequenceGenerator(name = &quot;primary_sequence&quot;, sequenceName = &quot;primary_sequence&quot;,
              allocationSize = 1, initialValue = 10000)
      @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = &quot;primary_sequence&quot;)
      private Long id;
  
      @Column(nullable = false)
      private Integer sessieId;
  
      @Column(nullable = false)
      private String category;
  
      @Column
      private String score;
  
      @ManyToOne
      @JoinColumn(name = &quot;user_id&quot;, nullable = false)
      private User user;
  </code></pre>
  <p>my Game <code>DTO</code>:</p>
  <pre><code>public class GameDTO {
  
      private Long id;
  
      @NotNull
      private Integer sessieId;
  
      @NotNull
      @Size(max = 255)
      private String category;
  
      @Size(max = 255)
      private String score;
  
      @NotNull
      private Long user;
  </code></pre>
  <p>The create method from my Game <code>service</code>:</p>
  <pre><code>public Long create(final GameDTO gameDTO) {
          final Game game = new Game();
          mapToEntity(gameDTO, game);
          return gameRepository.save(game).getId();
      }
  </code></pre>
  <p>So I saw the Game entity expects a long from user, so I tried to post the object user in the post for game.
  the post body:</p>
  <pre><code>{category: &quot;sport&quot;, sessieId: 20004,…}
  category: &quot;sport&quot;
  score: null
  sessieId: 20004
  user: {id: 10004, firstName: &quot;test5&quot;, lastName: &quot;test5&quot;, email: &quot;test5@test.nl&quot;, password: &quot;test&quot;}
  </code></pre>
  <p>But then I got the following error:</p>
  <blockquote>
  <p>JSON parse error: Cannot deserialize instance of <code>java.lang.Long</code> out of START_OBJECT token;</p>
  </blockquote>
  <p>Do I need to pass in a user object on the post? and how can I then fix the error?</p>