Friday, February 21, 2014

Jackson + Spring + Maven = http error 406 - workarounded

I get this error in Spring project with Jackson, with annotations:


Problem accessing /xxx/4. Reason:
    Not Acceptable

Powered by Jetty://

I have tested it with Jackson 2.3.1, 2.2.3 and 2.1.3 - same. Spring 3.1.1 and 3.1.0 - same. Application server jetty and tomcat - same, but in Tomcat dies with no error/log text.

So my conclusion is:

Jackson sucks!

And this is not for its error (there are no errors in controller method, it passes fine), but in dieing with no single line of message.

I will revert to jackson 1, where this error is not absolute blocker to me (i get it only on one page in version 1).

P.S. No answer on stackoverflow uptill 2014.2 helped me :(

Edit: the solution.
Holly *hit, I finally overcome the issue in very simple way!

Clean, not working way:
    public Dummy getT() {
        Dummy t = new Dummy();
        System.out.println( "hello from t" );
        return t;

    @RequestMapping(value = "/manualDummy", method = RequestMethod.GET)
    public String manualDummy(/*HttpServletRequest request, ModelMap model*/) throws JsonProcessingException {
        ObjectMapper mapper = new ObjectMapper(); // com.fasterxml.jackson.databind.ObjectMapper
        Dummy t = new Dummy();
        return mapper.writeValueAsString(t);

P.S. Jackson continues to sucks...

1 comment: