I am passing JSON data from jQuery to my Java controller and I am using @RequestBody
, but I am getting an exception saying:
org.springframework.web.HttpMediaTypeNotSupportedException: Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported
The data which I am passing is:
myData = {
"source": "CSS",
"type": "CSS2",
"typeValue": "value",
"textarea_value": " desc"
}:
The AJAX call I am using to pass this data is:
$.ajax({
url: './common/deleteData',
type: 'POST',
data: myData,
success: function(data) {
alert("Successfully Deleted Source..");
},
error: function(data) {}
});
My Java Controller is as below
@RequestMapping(value = "/common/deleteData", method = RequestMethod.POST, consumes = {"application/x-www-form-urlencoded; charset=UTF-8"})
public String deleteData(@RequestBody SourceDelete sourcedelete, final HttpServletRequest request, final RedirectAttributes rdtAttribs) throws ApplicationException
{
LOGGER.entry("Deleting the Merge Preference Details");
System.out.println(sourcedelete.getSource());
return null;
}
My POJO object is as below:
public class SourceDelete {
private String source;
private String type;
private String typeValue;
private String textarea_value;
//Setters and Getters
}
Can someone please help me figure out why I am getting this error and how I should fix it.