I have problems with sending and receiving a list of json objects (jQuery Ajax)
Java Object
public class UserSkill () {
private long user;
private long skill;
private long level;
//getter and setter methods
}
From Controller i get list of objects and it looks like this
$.getJSON("getList", function(data) {
console.log(data);
});
//console log -> [Object { user=4, skill=61, leve=10}, Object { user=3, skill=61, level=20}]
I changed some values and we have following code
ioarray = [];
//update methods
console.log(ioarray);
//console log -> [Object { user=4, skill=61, level=9000 }, Object { user=3, skill=61, level=100 }]
Ajax POST
$.ajax({
url : 'goUpdate',
type : 'POST',
contentType : 'application/json; charset=utf-8',
dataType : 'json',
data: ioarray,
succcess : function(e) {
alert('Yeah');
}
Controller
@RequestMapping(value = "goUpdate", method = RequestMethod.POST)
public Object goUpdatePOST(@RequestBody List<UserSkill> list) {
//list.get(0).getLevel();
return list;
}
Logs
type Status report
message Request method 'POST' not supported
description The specified HTTP method is not allowed for the requested resource.
Something wrong here ... any ideas?
UPDATE;
Controler
@RequestMapping(value = "goUpdate", method = RequestMethod.POST)
public @ResponseBody String goUpdatePOST(@RequestBody UserSkill[] list) {
for(UserSkill i : list) {
System.out.println(i.getSkill());
}
return "somepage";
}
jQuery
var ioarray = [{ user:4, skill:61, level:10},
{ user:3, skill:61, level:20}];
$.ajax({
url : 'goUpdate',
type : 'POST',
data: JSON.stringify(ioarray),
});
Console output
JSON
0
Object { user=4, skill=61, level=10}
1
Object { user=3, skill=61, level=20}
Source
[{"user":4,"skill":61,"level":10},{"user":3,"skill":61,"level":20}]
to pom.xml inserted jackson-mapper-asl and jackson-core-asl.
Of course this example generate same error... What i am doing wrong? I think I checked every possibility.
dataType : 'json'@RequestBodythen, there is some issue with the data posted and its type.dataType : 'json'