Spring MVC 415 Unsupported Media Type Spring MVC 415 Unsupported Media Type ajax ajax

Spring MVC 415 Unsupported Media Type


You may try with HttpServletRequest. it does not have any problem

  @RequestMapping(value = "/save-profile", method = RequestMethod.POST,consumes="application/json",headers = "content-type=application/x-www-form-urlencoded")    public @ResponseBody String saveProfileJson(HttpServletRequest request){       System.out.println(request.getParameter("profileCheckedValues"));        return "success";    }


1) Add the following dependencies

<dependency>    <groupId>com.fasterxml.jackson.core</groupId>    <artifactId>jackson-core</artifactId>    <version>${jackson-version}</version> // 2.4.3</dependency><dependency>    <groupId>com.fasterxml.jackson.core</groupId>    <artifactId>jackson-databind</artifactId>    <version>${jackson-version}</version> // 2.4.3</dependency>

2) If you are using @RequestBody annotation in controller method make sure you have added following in xml file

<mvc:annotation-driven />

This should resolve the 415 status code issue.


You will need to add jackson and jackson-databind to the classpath. Spring will pick it up using it's MappingJacksonHttpMessageConverter

MappingJacksonHttpMessageConverter

An HttpMessageConverter implementation that can read and write JSON using Jackson's ObjectMapper. JSON mapping can be customized as needed through the use of Jackson's provided annotations. When further control is needed, a custom ObjectMapper can be injected through the ObjectMapper property for cases where custom JSON serializers/deserializers need to be provided for specific types. By default this converter supports (application/json).