JSON post do Spring Controller
Cześć Zaczynam od usług internetowych na wiosnę, więc próbuję tworzyć małe aplikacje w Spring + JSON + Hibernate. Mam problem z HTTP-POST. Stworzyłem metodę:
@RequestMapping(value="/workers/addNewWorker", method = RequestMethod.POST, produces = "application/json", consumes = "application/json")
@ResponseBody
public String addNewWorker(@RequestBody Test test) throws Exception {
String name = test.name;
return name;
}
A mój model Test wygląda tak:
public class Test implements Serializable {
private static final long serialVersionUID = -1764970284520387975L;
public String name;
public Test() {
}
}
Przez POSTMAN wysyłam po prostu JSON {"name": "testName"} i zawsze otrzymuję błąd;
The server refused this request because the request entity is in a format not supported by the requested resource for the requested method.
Zaimportowałem bibliotekę Jacksona. Moje metody GET działają dobrze. Nie wiem, co robię źle. Jestem wdzięczny za wszelkie sugestie.