So basically i checked other questions and the most answers are to use @RequestBody
in my Post method on backend but it still throws 500 error with all my received json data is null
Any other suggestions what can be the problem?
here's my Rest:
@PostMapping({ "/createScreen" })
public ResponseEntity<String> createScreen(@RequestBody AdminWrapper adminWrapper) {
System.out.println(adminWrapper);
adminDao.saveAll(adminWrapper.getAdminList());
return new ResponseEntity<String>(HttpStatus.OK);
}
and this is the json i want to send back:
{
"module": "testModule",
"networkId": 1,
"adminInfos":
[{
"id": 1,
"key": "Test",
"value": "TestValue",
"defValue": "TestDef",
"type": "checkbox",
"isActive": true
}]
}
but in the log i see this:
adminWrapper [module=null, networkId = null, adminInfos = null ]
Request from frontend:
function submit() {
let adminWrapper = {
module: 'testModule',
networkId: 1,
adminInfos: []
}
$('#content > .form-group').each(function () {
let value = $(this).find('input').val();
if ($(this).find('input').attr('type') === 'checkbox')
value = $(this).find('input').prop('checked')
let adminInfo = {
id: $(this).find('input').attr('data-id'),
key: $(this).find('input').attr('data-key'),
value: value
}
adminWrapper.adminInfos.push(adminInfo);
})
$.ajax({
type: "POST",
url: 'http://localhost:8080/.../createScreen',
contentType: "application/json",
data: JSON.stringify({
adminWrapper
})
})
}