Shiladittya Chakraborty
Shiladittya Chakraborty

Reputation: 4418

Spring 4.3.5 and Jackson 2.8.7 are not working properly

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}"
}

Upvotes: 0

Views: 2863

Answers (1)

StaxMan
StaxMan

Reputation: 116620

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.

Upvotes: 1

Related Questions