Announcement Announcement Module
No announcement yet.
HTTP 4115: Unsupported Media Type (application/json) Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • HTTP 4115: Unsupported Media Type (application/json)

    I'm using Spring MVC that takes JSON request and return JSON response. I'm running into a weird bug where the first request will result in a HTTP 415 Unsupported Media Type, but ever subsequent request works fine.

    Application context (json-context.xml)
    <beans xmlns=""
        <bean id="jacksonMessageConverter" 
        <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
            <property name="messageConverters">
                    <ref bean="jacksonMessageConverter" />
    	<context:component-scan base-package=my.controller" />
    	<context:component-scan base-package="" />
    	<mvc:annotation-driven />
        <!-- DispatcherServlet for regular Spring MVC (for GWT client that sends and receives JSON as data) -->
    	<!-- Map all gwt request to the GWT DispatcherServlet for handling  -->
    public class CodeController {
    	private CodeService codeService;
         * Expects the Content-type: 'application/json'
         * Returned Content-type: 'application/json'
        @RequestMapping(value = "/geCodes", method = RequestMethod.POST)
        public @ResponseBody List<Code> getCodes(@RequestBody final CodeQuery codeQuery){
        	List<Code> codes = codeService.queryForCode(codeQuery);
        	return codes;
    // this class holds the search criteria
    public class CodeQuery implements Query{
        private String code;
        private String label;
        private List<AoInfo> aoInfo;  // where AoInfo is an interface, 4 classes implements the AoInfo interface.

    I use FireFox (with Rest Client plugin) and make a POST call (with Content-Type set to "application/json").
    The first call will fail - results in unsupported Media Type (application/json), resend request again ad it works.
    only the first request (after the server start will fail). What am i doing wrong?
    Last edited by tqnguyen1973; Apr 15th, 2012, 06:50 PM.

  • #2
    Could you post the complete error stack trace shown in the server? If is not available, check the log files in the server.


    • #3
      Actually, I tracked down the cause o the HTTP 415 Unsupported Media Type. My CodeQuery class also has one additional field List<AoInfo> where AoInfo is an interface and it has multiple classes that implements the interface.
      The Jackson deserializer was not able to deserialize the list of <AoInfo>, probably cause it cannot determine the actual implementation to use...understandable. However, no exception was being thrown or logged. It seem the Jackson mapper call the method canRead(Object, Class). The lack of logging was what thrown me off and wasted so much time in tracking down the bug.

      I had to resort to using the JSONObject and JSONArray to manually deserialize the JSON string. I changed the @RequestBody Code query to HttpServetRequest req, so i can get the body content from the request.