Are you sure that there are no exceptions in your Spring code. When converting from JSON to a custom object in Spring, you need to specify a custom class that has the same fields and format as the incoming JSON. Otherwise, Spring doesn't know who to convert the HTTP POST data into a Java object.
In your case, you can define a POJO as follows:
public class MyRequestObj { private String customerName;
And put this in your controller class:
@RequestMapping(value = "/package/{id}", method = RequestMethod.PUT) @ResponseStatus(HttpStatus.OK) @ResponseBody public SPackage updatePackage(@PathVariable String id, @RequestBody MyRequestObj myRequestObj) { String customerName = myRequestObj.getCustomerName(); }
Of course, if you only want to pass the client name as String to your controller, you can also pass it as a query string (append? CustomerName = someCustomer), and you can get it in Spring as:
@RequestMapping(value = "/package/{id}", method = RequestMethod.PUT) @ResponseStatus(HttpStatus.OK) @ResponseBody public SPackage updatePackage(@PathVariable String id, @RequestParam("customerName") String customerName) { }
source share