NimChimpsky
NimChimpsky

Reputation: 47280

http 406, spring non parseable media BUT I have mvc annotation, and jackson on my classpath

I have :

<context:annotation-config/>
<mvc:annotation-driven/>

In my appContext and my pom includes jackson :

<dependency>
            <groupId>org.codehaus.jackson</groupId>
            <artifactId>jackson-mapper-asl</artifactId>
            <version>${org.codehaus.jackson-version}</version>
        </dependency>
      <dependency>
            <groupId>org.codehaus.jackson</groupId>
            <artifactId>jackson-core-asl</artifactId>
            <version>${org.codehaus.jackson-version}</version>
        </dependency>

and my controller has @ResponseBody on return type of List<Long>, but I still get a nonparseablemedia 406 error with a get request, what am I missing ?

@RequestMapping(value = "/myUrl/{customerId}/{productId}/", method = RequestMethod.GET)
@ResponseStatus(HttpStatus.OK)
public @ResponseBody List<Long> myMethod(@PathVariable Long customerId, @PathVariable Double productId) {
        List<Long> result = fieldService.identifyField(customerId, productId);
        return result;
    }

and it is being called by a unit test (where ids are appropraite variables):

MockHttpServletRequestBuilder mockHttpServletRequestBuilder
                = get("/myUrl/"+customerId+"/"+productId);

        MvcResult mvcResult = this.mockMvc.perform(mockHttpServletRequestBuilder)
                .andDo(print())
                .andExpect(status().isOk())
                .andReturn();

The print of the request shows the method is being found but 406, argh!

Handler:
  Type = com.mycompany.MyController
  Method = public java.util.List<java.lang.Long>   uk.co.axiomtechsolutions.ipf.webapp.web.MyController.MyMethod(java.lang.Long,java.lang.Double)

Resolved Exception:
  Type = org.springframework.web.HttpMediaTypeNotAcceptableException

Upvotes: 0

Views: 172

Answers (1)

NimChimpsky
NimChimpsky

Reputation: 47280

For anyone else its seems to be caused by using Double datatype as Url variable ... the full stop makes spring thinks its a file extension ? CHanging datatype to integer means the tests pass.

Upvotes: 1

Related Questions