title: Spring Boot - There was an unexpected error (type=Bad Request, status=400). Required request body is missing
body: <p>I created a simple Spring Boot REST service to handle posting data from my HTML page.  When I POST data everything is ok, but when I want to check data on @RequestMapping value href I see error message: </p>
  
  <blockquote>
    <p>Whitelabel Error Page</p>
    
    <p>This application has no explicit mapping for /error, so you are seeing this as a fallback.</p>
    
    <p>Wed Nov 15 13:33:46 CET 2017
    There was an unexpected error (type=Bad Request, status=400).
    Required request body is missing: public org.springframework.http.ResponseEntity> pl.sample.atms.web.rest.QuestionRestController.getQuestions5(pl.sample.atms.dto.Question)</p>
  </blockquote>
  
  <p>How Can I check and get sent data? My code:</p>
  
  <p>JS:</p>
  
  <pre><code>$.ajax({
      url: 'http://localhost:8080/api/questionsPost',
      dataType: 'json',
      type: 'post',
      contentType: 'application/json',
      data: JSON.stringify(scoreObj),
      success: function( data, textStatus, jQxhr ){
          console.log(data, textStatus, jQxhr)
      },
      error: function( jqXhr, textStatus, errorThrown ){
          console.log( jqXhr, textStatus, errorThrown );
      }
  }); 
  </code></pre>
  
  <p>Rest controller:</p>
  
  <pre><code>package pl.sample.atms.web.rest;
  
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.http.ResponseEntity;
  import org.springframework.web.bind.annotation.*;
  import pl.sample.atms.dao.QuestionRepository;
  import pl.sample.atms.dto.Question;
  import java.util.ArrayList;
  import java.util.List;
  
  @RestController
  @RequestMapping(value = "/api",  method = {RequestMethod.GET, RequestMethod.POST})
  public class QuestionRestController {
  
      @Autowired
      private QuestionRepository questionRepository;
  
      @PostMapping("/questionsPost")
      public ResponseEntity&lt;List&lt;Question&gt;&gt; getQuestions5(@RequestBody Question myQuestion) {
          System.out.println(ResponseEntity.ok(new ArrayList&lt;&gt;()));
          System.out.println(myQuestion);
          return ResponseEntity.ok(new ArrayList&lt;&gt;());
      }
  
  }
  </code></pre>
  
  <p>Question dto</p>
  
  <pre><code>package pl.sample.atms.dto;
  
  import javax.persistence.Entity;
  import javax.persistence.Id;
  
  @Entity
  public class Question {
  
      @Id
      private Long id;
  
      private String title;
  
      public Question() {
      }
  
      public Long getId() {
          return id;
      }
  
      public void setId(Long id) {
          this.id = id;
      }
  
      public String getTitle() {
          return title;
      }
  
      public void setTitle(String title) {
          this.title = title;
      }
  }
  </code></pre>
  
  <p>Question repository</p>
  
  <pre><code>package pl.sample.atms.dao;
  
  import org.springframework.data.repository.CrudRepository;
  import pl.sample.atms.dto.Question;
  
  import java.util.List;
  
  public interface QuestionRepository extends CrudRepository&lt;Question, Long&gt; {
      List&lt;Question&gt; findByTitle(String title);
  }
  </code></pre>
  
  <p>UPDATE</p>
  
  <p>I changed Rest controller code:</p>
  
  <pre><code>package pl.sample.atms.web.rest;
  
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.http.ResponseEntity;
  import org.springframework.ui.Model;
  import org.springframework.web.bind.annotation.*;
  import pl.sample.atms.dao.QuestionRepository;
  import pl.sample.atms.dao.UserInfoRepository;
  import pl.sample.atms.dto.Question;
  import pl.sample.atms.dto.QuestionAnswer;
  import pl.sample.atms.dto.Response;
  import pl.sample.atms.dto.UserInfo;
  
  import java.util.ArrayList;
  import java.util.List;
  
  import static org.apache.commons.lang3.StringUtils.isBlank;
  
  @RestController
  @RequestMapping("/api")
  public class QuestionRestController {
  
      @Autowired
      private QuestionRepository questionRepository;
  
      @Autowired
      private UserInfoRepository userInfoRepository;
  
      private List&lt;Question&gt; question = new ArrayList&lt;Question&gt;();
  
      @GetMapping(value = "/questionsGet")
      public Response getResource() {
          Response response = new Response("Done", question);
          return response;
      }
  
      @PostMapping(value = "/questionsPost")
      public Response postCustomer(@RequestBody Question oneQuestion) {
          question.add(oneQuestion);
  
          Response response = new Response("Done", oneQuestion);
          return response;
      }
  
  }
  </code></pre>
  
  <p>And I created new class - response:</p>
  
  <pre><code>package pl.sample.atms.dto;
  
  public class Response {
      private String status;
      private Object data;
  
      public Response(){
  
      }
  
      public Response(String status, Object data){
          this.status = status;
          this.data = data;
      }
  
      public String getStatus() {
          return status;
      }
  
      public void setStatus(String status) {
          this.status = status;
      }
  
      public Object getData() {
          return data;
      }
  
      public void setData(Object data) {
          this.data = data;
      }
  }
  </code></pre>
  
  <p>Now I am able to see some sent data, but unfortunatelly it isn't generated and sent using JavaScript JSON, but this:</p>
  
  <pre><code>{"status":"Done","data":[{"id":null,"title":null}]}
  </code></pre>
  
  <p>Structure of JSON which I need: </p>
  
  <pre><code>"{"N":["4","4","5","4","2"],"E":["4","4","5","3","1"],"O":["3","3","4","2","3"],"U":["2","2","2","2","4"],"S":["3","2","2","3","3"]}"
  </code></pre>
  
  <p>I really don't know what I am doing wrong but I feel that I am close to solve this.</p>