I have in my project a controller that receives data via jquery. But this data is converted into an object containing subobject. that is:
class Teste{
String a;
String b;
Test2 teste2;
}
class Test2{
String c;
String d;
}
No controller is getting with the following code.
@ResponseBody
@RequestMapping(value = "/novo",
method = RequestMethod.POST,
consumes = MediaType.APPLICATION_JSON_VALUE,
produces = MediaType.APPLICATION_JSON_VALUE
)
public Teste cadastrar(Teste teste) {
System.out.println("\n\n*******************TESTE*******************\n" + teste);
return teste;
}
In this way the data is only sent by query params. So I can not pass the subobjects. The ajax function used is as follows.
$.ajax({
type: 'POST',
url: '/teste/novo?' + jQuery.param(teste),
contentType: 'application/json',
data: JSON.stringify(product),
success: function (data) {
//innerOptionsInHTML(data);
}
}).done(function () {
console.log("success");
}).fail(function () {
console.log("error");
});
In this way the subobjects are not passed to the server. In fact it only started being passed when using QueryParams. Before that the function would send with type application_json. But it still did not work.
All this using spring MVC and I need to pass the subobjects.
It would be more interesting if you could configure Spring MVC to receive the object via javascript in the form:
{
a:"a",
b:"b",
teste:{
c:"c",
d:"d"
}
}
without the use of params query.