I have following json request on view side
index.html
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <script src="http://code.jquery.com/jquery-1.9.1.js"></script> <script type="text/javascript" > $(document).ready(function(){ sendAjax(); }); function sendAjax() { $.ajax({ url: "/shop/main/order/model", type: 'POST', dataType: 'json', data: " { \"totalPrice\": 10, \"custumerName\":\"vasiya\", \"ItemsList\": [ { \"id\": 1,\"name\":\"qqq\", \"price\": 10, \"count\": 2 } ] }", contentType: 'application/json', mimeType: 'application/json', success: function(data) { alert(data.totalPrice + " " + data.custumerName); }, error:function(data,status,er) { alert("error: "+data+" status: "+status+" er:"+er); } }); } </script> </body> </html> controller looks like this
@Controller @RequestMapping("/order") public class OrderController { @RequestMapping(value="/model", method = RequestMethod.POST) public @ResponseBody OrderModel post(@RequestBody final OrderModel model) { System.out.println(model.getItemsList()); System.out.println(model.getTotalPrice()); return model; } } } OrderModel.java
public class OrderModel implements Serializable { private static final long serialVersionUID = 1L; String custumerName; int totalPrice; Items[] itemsList; public void setTotalPrice(int totalPrice) { this.totalPrice = totalPrice; } public void setItemsList(Items[] itemsList) { this.itemsList = itemsList; } public int getTotalPrice() { return totalPrice; } public Items[] getItemsList() { return itemsList; } public void setCustumerName(String custumerName) { this.custumerName = custumerName; } public String getCustumerName() { return custumerName; } public OrderModel(String custumerName, int totalPrice, Items[] itemsList) { this.custumerName = custumerName; this.totalPrice = totalPrice; this.itemsList = itemsList; } } Items.java is a simple POJO class which is designed for mapping hibernate entities and contains String and long types fields only.
So when I'm trying to access index.html it doesn't send back any respone. In browser's console i'm getting the follow:
POST http://localhost:8080/shop/main/order/model 415 ()
HTTP Status 415 -
type Status report
message
description: The server refused this request because the request entity is in a format not supported by the requested resource for the requested method.
data: { totalPrice: 10, custumerName:'vasiya', ItemsList: [ {id: 1,name:'qqq', price: 10, count: 2 } ] },consumes="application/json"in the@RequestMapping