Я пытаюсь отправить объект JSON из внешнего интерфейса в бэкэнд через jQuery AJAX.
Вызов ajax успешно выполняется по запрошенному пути "/ survey" методом POST.
Проблема в том, что мой @RequestBody final HmmSurveyForm hmmSurveyForm
имеет нулевые значения для моих полей "answer1" и "heading".
При проверке запроса в Google Chrome отправляется запрос разработчика:


Но для заполненных полей из внешнего интерфейса ответ нулевой:

У меня следующий код во внешнем интерфейсе:
postSurvey: function() {
$.ajax({
url: this.encodedContextPath + "/survey",
type: 'POST',
dataType: 'json',
contentType: 'application/json',
data: ACC.hmmSurvey.getJSONDataForSurvey(),
async: true,
success: function (response) {
console.log(response);
},
error: function (jqXHR, textStatus, errorThrown) {
console.log("The following error occurred: " + textStatus, errorThrown);
}
});
}
getJSONDataForSurvey: function () {
var json = [];
json.push({"answer1": "1"});
json.push({"heading": "Test"});
return JSON.stringify({"hmmSurveyForm": json});
}
и в бэкэнде:
@RequestMapping(value = "/survey", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
public @ResponseBody HmmSurveyForm postSurvey(@RequestBody final HmmSurveyForm hmmSurveyForm, final Model model) {
System.out.println(hmmSurveyForm);
return hmmSurveyForm;
}
public class HmmSurveyForm {
private String heading;
private String answer1;
// getter, setters
}