Announcement Announcement Module
No announcement yet.
406 NOT_ACCEPTABLE from Controller when trying to return POGO as JSON Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • 406 NOT_ACCEPTABLE from Controller when trying to return POGO as JSON

    Hi folks,

    I have an annotated Controller in a Groovy Spring MVC app which uses annotated Configuration. I'm trying to get my controller to automatically marshall a POGO to JSON using Jackson but when I invoke the Controller's methods I get a 406 NOT_ACCEPTABLE response back from Spring.

    From what I understand this is typically because Spring's HttpMessageConverters are not configured correctly, this seems to be a common config problem and I have followed all the advice from other posts to no avail. So hoping someone can help me figure this out.

    Spring Config class:

    class TSPMServiceAppConfig {
    Controller class:

    //imports removed for brevity
    public class TSPMAuthenticationController implements ITSPMAuthenticationController {
      @RequestMapping(value = "/sayHi", method = RequestMethod.GET, produces=["application/json"])
      public UserPermissionCheckResponse sayHi() {
        println "TSPMAuthenticationController: sayHi()"
        UserPermissionCheckResponse response = new UserPermissionCheckResponse(message: "Hi")
        return response
    Response POGO:

    class UserPermissionCheckResponse {
      boolean permitted
      String message
    The app loads fine, I can see the controller registering the URL mappings and I can invoke the controller methods by hitting the associated URLS (tested through remote debugging).

    I have tried making the following resquest:

    GET http://localhost:8088/em3/gateway/security/tspm/remoting/TSPMAuthenticationController/sayHi
    Request Headers: "Accept: application/json"
    When I make this request I get the following response headers

    Status Code: 406 Not Acceptable
    Cache-Control: must-revalidate,no-cache,no-store
    Content-Length: 1444
    Content-Type: text/html; charset=iso-8859-1
    Server: Jetty(6.1.25)
    I attach a Gradle project which demonstrates the issue: Attachment

    To run the app in Jetty:
    ./gradlew jettyRun
    Then do the above GET request to replicate the issue

    To run a full build which will fail during integration tests for the reason above:
    ./gradlew clean build
    You will see from the build.gradle file and the resulting war that I have both Jackson and JAXB on the application classpath. Again from what I've read the fact that I'm using the @EnableWebMvc annotation should cause Spring to register the default HttpMessageConverters which I believe in this case should include MappingJacksonHttpMessageConverter as Jackson is present on the classpath?

    I'm sure this is something trivial but I just can't see what's wrong. Would be most grateful for a second pair of eyes on this.

    Many thanks,

    Attached Files

  • #2
    hmm... not a single reply. have I not done a great job of explaining the issue perhaps? Grateful for any suggestions and happy to clarify anything above which might help folk help me out with this issue. Cheers.