Spring's Json not being resolved with appropriate response

前端 未结 8 2049
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-03 11:12

I\'ve tried to have a controller in Spring return a JSON response to no avail using the Jackson classes as recommended with 3.0. I\'ve got the jackson jar files(jackson-core

相关标签:
8条回答
  • 2020-12-03 11:49

    Also, make sure that you add two jackson related jar files.

    • jackson-core-asl-1.9.8.jar
    • jackson-mapper-asl-1.9.8.jar

    The version can be different.

    0 讨论(0)
  • 2020-12-03 11:54

    I know that this is an old thread, but maybe someone will encounter the same problem as me. I got that exception when migrating an application from Spring 4.0.3.RELEASE to Spring 4.1.0.RELEASE. In my case updating Jackson from 1.9.x to 2.4.x did the trick.

    0 讨论(0)
  • 2020-12-03 11:56

    Sending the Accept: application/xml header does not work. But sending Accept: application/json actually works, and jackson mapper kicks in. I got rid of my 406 and got my serialized java object in json format with no more config than @ResponseBody and return new MyObject() :) Thanks skaffman for this information, and thanks Bozho for the working header value :D

    0 讨论(0)
  • 2020-12-03 12:03

    Get rid of all Jackson beans, and of the json mapping in the negotiating resolver. the mvc:annotation-driven should configure everything you need for the Jackson serialization to work.

    0 讨论(0)
  • 2020-12-03 12:06

    May be my answer is a bit late, but it may help some one else visiting this question.

    I got my problem resolved by adding

     hibernate-validator-4.0.2 
    

    and gave me another exception (class not found exception: org.slf4j.LoggerFactory) which i resolved by adding

    slf4j-api-1.5.6.jar
    

    I hope it will help someone.

    0 讨论(0)
  • 2020-12-03 12:09

    I have got same exception when migrating from spring 3.x to spring 4.x.

    I solved it with updating jackson dependencies from

        <dependency>
            <groupId>org.codehaus.jackson</groupId>
            <artifactId>jackson-mapper-asl</artifactId>
            <version>1.9.13</version>
        </dependency>
    

    to

        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-core</artifactId>
            <version>2.5.1</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>2.5.1</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-annotations</artifactId>
            <version>2.5.1</version>
        </dependency>
    

    Nothing else was needed for me.

    0 讨论(0)
提交回复
热议问题