415 Unsupported Media Type

415 Unsupported Media Type

415 Unsupported Media Type

You see this error when working with AngualarJS and Spring MVC web application while posting data using AngularJS http service.

Note: If you came from JQuery background and thinking about swapping jQuery.post() with AngularJS $http.post() will not work because both serialize and transmit data in different format:

  • JQuery data serialization : headers: {‘Content-Type’: ‘application/x-www-form-urlencoded’}
  • AngularJS data serialization : headers: {‘Content-Type’: ‘application/json’}

Possible reasons: 

  • You have not included Jackson libraries in your classpath
  • When you send request from AngularJS to Spring MVC controller JSON converts to Java Object using message converter. Check your spring XML configuration if you have added below tag or not

  • Probably JSON data not correctly created. Please check your JSON object before sending request to the controller. You could use JSONLint to validate your JSON data format.
  • Check JSON object property name is correctly matching with your Spring MVC controller domain object
  • Finally check your request mapping in controller it should be as below if you have example domain name person:

3 thoughts on “415 Unsupported Media Type

  1. I was using Angular with Spring and getting same exception.
    After putting Jackson lib, exception is resolved

Leave a Reply

Your email address will not be published. Required fields are marked *