Serialization errors due to jackson-databind version mismatch?

I encountered the following error

java.lang.NoSuchFieldError: WRITE_DURATIONS_AS_TIMESTAMPS at com.fasterxml.jackson.datatype.joda.ser.DurationSerializer.<init>(DurationSerializer.java:28) at com.fasterxml.jackson.datatype.joda.ser.DurationSerializer.<init>(DurationSerializer.java:25) at com.fasterxml.jackson.datatype.joda.JodaModule.<init>(JodaModule.java:45) 

I checked which versions of jackson-datatype-joda are available. It seems that maven has eliminated all version mismatches.

Any other reason could lead to serialization errors?

+5
source share
3 answers

I got this solution using the following dependency, since this dependency redefined any other version used:

 <dependency> <groupId>com.fasterxml.jackson.datatype</groupId> <artifactId>jackson-datatype-joda</artifactId> <version>2.5.3</version> </dependency> 
+3
source

The problem is that among the maven dependencies (remember that this can be transitive) you have incompatible versions of jackson-datatype-joda and jackson-databind . Incompatible in the sense that the jackson-databind SerializationFeature class does not contain the WRITE_DURATIONS_AS_TIMESTAMPS field. To find out which dependencies you are using, you can run the following command in the terminal (or you can use the IDE plug-in to search and analyze the maven dependency tree):

 mvn dependency:tree | grep databind 

the result is likely to be something like this:

 [INFO] | +- com.fasterxml.jackson.core:jackson-databind:jar:2.4.1:compile 

The course version may change, but it’s important that the WRITE_DURATIONS_AS_TIMESTAMPS field is available only from version 2.5

You can exclude the transitive dependency as follows:

 <dependency> <groupId>group.id</groupId> <artifactId>artifact-id</artifactId> <version>${artifact.version}</version> <exclusions> <exclusion> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId> </exclusion> </exclusions> </dependency> 

If this is not a transitive dependency, you need to update the jackson-databind version.

+9
source

I had the same error. I have included all jackson * 2.7.0 libraries in WEB-INF / lib / and I still got this error. I am using wildfly 8.2, and it had jackson 2.4.1 libraries under the modules, and somehow it was loading 2.4.1 cans from this place. So I had to manually update them to 2.7.0, which fixed the problem. It seemed to me that if I had not mentioned this in order to load Jackson jars into the deployment configuration file, he would not load the wild bars. I guess I was wrong.

0
source

Source: https://habr.com/ru/post/1234538/


All Articles