I\'m getting a NoSuchMethodError
error when running my Java program. What\'s wrong and how do I fix it?
I had the same error:
Exception in thread "main" java.lang.NoSuchMethodError: com.fasterxml.jackson.core.JsonGenerator.writeStartObject(Ljava/lang/Object;)V
at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:151)
at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.serializeValue(DefaultSerializerProvider.java:292)
at com.fasterxml.jackson.databind.ObjectMapper._configAndWriteValue(ObjectMapper.java:3681)
at com.fasterxml.jackson.databind.ObjectMapper.writeValueAsString(ObjectMapper.java:3057)
To solve it I checked, firstly, Module Dependency Diagram (click in your POM the combination -> Ctrl+Alt+Shift+U
or right click in your POM -> Maven -> Show dependencies
) to understand where exactly was the conflict between libraries (Intelij IDEA). In my particular case, I had different versions of Jackson dependencies.
1) So, I added directly in my POM of the project explicitly the highest version - 2.8.7 of these two.
In properties:
2.8.7
And as dependency:
com.fasterxml.jackson.core
jackson-databind
${jackson.version}
2) But also it can be solved using Dependency Exclusions.
By the same principle as below in example:
group-a
artifact-a
1.0
com.fasterxml.jackson.core
jackson-databind
Dependency with unwanted version will be excluded from your project.