Jackson ObjectMapper() constructor throws NoSuchMethod

后端 未结 9 1832
忘掉有多难
忘掉有多难 2020-12-09 03:40

I\'m using Jackson sample code to deserialize a POJO:

ObjectMapper m = new ObjectMapper();

This line throws a NoSuchMethodError:

         


        
9条回答
  •  暖寄归人
    2020-12-09 04:00

    I have faced this problem when migrating my WebApp from Tomcat 6 to Tomcat 8. On Tomcat6 and Tomcat7 my WebApp would start just fine, but on Tomcat8 I would get this exception(seems that T6 and T7 loads classes alphabeticaly but T8 doesn't - https://stackoverflow.com/a/26642798/1864614).

    The problem was that I was having 2 versions of the class

    org.codehaus.jackson.map.ObjectMapper
    As answered by @wild_nothing I have checked dependency the tree to list all dependencies on org.codehaus.jackson

    In my case the problem was that I had several versions of libraries that provided this class:

    • org.codehaus.jackson:jackson-mapper-lgpl:jar:1.5.0
    • org.codehaus.jackson:jackson-core-lgpl:jar:1.5.0
    • org.codehaus.jackson:jackson-mapper-asl:jar:1.8.2
    • org.codehaus.jackson:jackson-core-asl:jar:1.8.2

    My solution was to exclude the older versions(1.5.0) and only leave the 1.8.2 version

    
            cfm.foo
            jive
            
                
                    org.codehaus.jackson
                    jackson-core-lgpl
                
                
                    org.codehaus.jackson
                    jackson-mapper-lgpl
                
            
        
    
    • in this case jive was depending on older 1.5.0 version

提交回复
热议问题