I need to submit a JS-formed Array of Objects to a Spring MVC Controller. All the property names match.
@PostMapping("/addAdmin")
public void addAdmin(@RequestParam List<UserRolesGUIBean> userRolesGUIBeans)
{
// ...
}
JS:
var entries = [];
//...
// entries is an array of objects of the form {id: "..", role: ".."}
// verified to be correct before submission
$.ajax({
type : "post",
dataType : "json",
url : 'addAdmin',
data : JSON.stringify(entries)
})
Bean
public class UserRolesGUIBean implements Serializable {
private String id;
private String role;
// + Constructors (Empty + Full), Getters and setters
}
Error:
Required List parameter 'userRolesGUIBeans' is not present]
Also tried this with ModelAttribute
and an ArrayList
,
PostMapping("/addAdmin")
public void addAdmin(@ModelAttribute ArrayList<UserRolesGUIBean> userRolesGUIBeans) {
Now there are no errors, but the list is empty, no data was received.
Tried everything -- arrays vs. lists, JSON.stringify(data)
or a data object with data {"entries" : entries}
, RequestBody
doesn't work and gives UTF Errors; and RequestParam
as above doesn't work either.
This is way too complicated for a simple task.