0

I am using springVersion = '4.3.5.RELEASE' and jacksonVersion ='2.8.7'

But it's everytime throwing below exception :

Caused by: java.lang.NoSuchMethodError: com.fasterxml.jackson.databind.ObjectWriter.forType(Lcom/fasterxml/jackson/databind/JavaType;)Lcom/fasterxml/jackson/databind/ObjectWriter;
    at org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.writeInternal(AbstractJackson2HttpMessageConverter.java:278) [spring-web-4.3.5.RELEASE.jar:4.3.5.RELEASE]
    at org.springframework.http.converter.AbstractGenericHttpMessageConverter.write(AbstractGenericHttpMessageConverter.java:100) [spring-web-4.3.5.RELEASE.jar:4.3.5.RELEASE]
    at org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodProcessor.writeWithMessageConverters(AbstractMessageConverterMethodProcessor.java:231) [spring-webmvc-4.3.5.RELEASE.jar:4.3.5.RELEASE]
    at org.springframework.web.servlet.mvc.method.annotation.HttpEntityMethodProcessor.handleReturnValue(HttpEntityMethodProcessor.java:203) [spring-webmvc-4.3.5.RELEASE.jar:4.3.5.RELEASE]
    at org.springframework.web.method.support.HandlerMethodReturnValueHandlerComposite.handleReturnValue(HandlerMethodReturnValueHandlerComposite.java:81) [spring-web-4.3.5.RELEASE.jar:4.3.5.RELEASE]
    at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:132) [spring-webmvc-4.3.5.RELEASE.jar:4.3.5.RELEASE]
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827) [spring-webmvc-4.3.5.RELEASE.jar:4.3.5.RELEASE]
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738) [spring-webmvc-4.3.5.RELEASE.jar:4.3.5.RELEASE]
    at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85) [spring-webmvc-4.3.5.RELEASE.jar:4.3.5.RELEASE]
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:963) [spring-webmvc-4.3.5.RELEASE.jar:4.3.5.RELEASE]
    ... 37 more

Not able to understand why it's throwing this exception. Got a help from this link Spring 4.2.3 and fasterxml Jackson 2.7.0 are incompatible and changed jacksonVersion to compatible version as answered by the expert but still I am getting the same issue.

My gradle file look like :

springVersion           = '4.3.5.RELEASE'
springDataVersion       = '1.10.5.RELEASE'
jacksonVersion          ='2.8.7'

dependencies {

compile "org.springframework:spring-context:${springVersion}"
compile "org.springframework:spring-context-support:${springVersion}"
compile "org.springframework:spring-core:${springVersion}"
compile "org.springframework:spring-web:${springVersion}"
compile "org.springframework:spring-webmvc:${springVersion}"
compile "org.springframework:spring-tx:${springVersion}"
compile "org.springframework:spring-beans:${springVersion}"
compile "org.springframework:spring-aop:${springVersion}"
compile "org.springframework:spring-test:${springVersion}"
compile "org.springframework.data:spring-data-jpa:${springDataVersion}"
compile "org.springframework:spring-orm:${springVersion}"

compile "com.fasterxml.jackson.core:jackson-core:${jacksonVersion}"
compile "com.fasterxml.jackson.core:jackson-databind:${jacksonVersion}"
compile "com.fasterxml.jackson.core:jackson-annotations:${jacksonVersion}"
}
Shiladittya Chakraborty
  • 4,270
  • 8
  • 45
  • 94
  • 1
    Run `gradle dependencies` to ensure you're not pulling in an older version of Jackson. We're using Spring 4.3.14.RELEASE and Jackson 2.9.2 without any issue but we've incrementally updated our dependencies over the years and have never run into problems with Spring/Jackson. – Paul Apr 02 '18 at 13:18
  • Its not pulling older version I have checked. – Shiladittya Chakraborty Apr 02 '18 at 13:36
  • I'm using maven in a clean project and those versions (Spring 4.3.14.RELEASE and Jackson 2.9.2) are throwing this error: `java.lang.ClassNotFoundException: com.fasterxml.jackson.databind.Module`. I might be doing something wrong too. – White_King Feb 05 '22 at 18:45

1 Answers1

1

This is definitely a version compatibility problem, so somehow version of jackson-databind you have during runtime is older than what you need. Even if you have updated dependency, perhaps it gets overridden by something else; or, maybe you have multiple jars in classpath (in which case one is arbitrarily chosen... and of course it is often the older one).

The reason I am fairly certain it is version problem is that it is JVM linker finding the problem: version being run was compiled against newer version that does have the method, but one being loaded does not have that method.

StaxMan
  • 113,358
  • 34
  • 211
  • 239