I can see two areas which may need amending. The first is in your JS, you're creating an object
dataObj
and populating it with the form information but you're not then using it. The
serializeArray()
method does not create an object but creates an array which I'm going to guess isn't what your
UserModel
class is. Instead use:
const userJson = JSON.stringify(dataObj);
The next part is the bit in the controller where you're trying to consume the content. The
@ModelAttribute
annotation is designed for models which have been added to a view and bound using something like Spring Forms. Try changing the controller declaration to:
public String registerUser(@RequestBody UserModel ums)
The
@RequestBody
annotation tells Spring to consume whatever content was POST'd and deserialize it into the parameter type.