Hello. In my spring project, I can't get the data in the @RequestBody argument. here is the controller:

@ResponseBody @RequestMapping(value = "submit" , method = RequestMethod.POST) public String submit(@RequestBody RequestData requestData) { System.out.println(requestData.getPeriod()); return "что-то там"; } 

js

  $.ajax({ type: "POST", contentType: "application/json; charset=utf-8", url: "<c:url value="/submit" />", data: JSON.stringify({ period: $("input[name='PERIOD']").val() }) }); 

This is what json looks like, which is sent to the server:

 {"period":"2016/07/08 21:04"} 

Here is the object itself:

 @Data public class RequestData{ private String period; } 

Jackson-databind-2.8.4 library is connected to the project.

From the server comes the answer: status 415, description
It is not supported for the requested method.

Tell me please, in connection with which this can occur?

  • Does class RequestData have class RequestData / set methods and an empty constructor? - MrFylypenko
  • one
    Yes, this is the Lombok library, which allows you not to write heterosexuals and setters, if you write down the @Nata - fantastic nov
  • Add the dataType: "json" parameter to the ajax request dataType: "json" - mit
  • no, did not help - fantastic
  • written about 415 error ru.stackoverflow.com/a/678086/182273 - Alex78191

0