FasterXML / jackson-modules-java8

Set of support modules for Java 8 datatypes (Optionals, date/time) and features (parameter names)
Apache License 2.0
401 stars 117 forks source link

java.lang.NoSuchFieldError: _valueInstantiator when deserialising Optional #81

Closed marcosscriven closed 6 years ago

marcosscriven commented 6 years ago

I'm currently using 2.9.6 and just enabled the Jdk8Module

Deserialising Optionals results in the trace below. Downgrading just the Jdk8Module artifact to the latest 2.8.x version fixes the issue.

java.lang.NoSuchFieldError: _valueInstantiator
    at com.fasterxml.jackson.datatype.jdk8.OptionalDeserializer.withResolved(OptionalDeserializer.java:38)
    at com.fasterxml.jackson.datatype.jdk8.OptionalDeserializer.withResolved(OptionalDeserializer.java:10)
    at com.fasterxml.jackson.databind.deser.std.ReferenceTypeDeserializer.createContextual(ReferenceTypeDeserializer.java:74)
    at com.fasterxml.jackson.databind.DeserializationContext.handlePrimaryContextualization(DeserializationContext.java:650)
    at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.resolve(BeanDeserializerBase.java:490)
    at com.fasterxml.jackson.databind.deser.DeserializerCache._createAndCache2(DeserializerCache.java:293)
    at com.fasterxml.jackson.databind.deser.DeserializerCache._createAndCacheValueDeserializer(DeserializerCache.java:244)
    at com.fasterxml.jackson.databind.deser.DeserializerCache.findValueDeserializer(DeserializerCache.java:142)
    at com.fasterxml.jackson.databind.DeserializationContext.findContextualValueDeserializer(DeserializationContext.java:443)
    at com.fasterxml.jackson.databind.deser.std.StdDeserializer.findDeserializer(StdDeserializer.java:964)
    at com.fasterxml.jackson.databind.deser.BeanDeserializerBase._findDelegateDeserializer(BeanDeserializerBase.java:623)
    at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.resolve(BeanDeserializerBase.java:547)
    at com.fasterxml.jackson.databind.deser.DeserializerCache._createAndCache2(DeserializerCache.java:293)
    at com.fasterxml.jackson.databind.deser.DeserializerCache._createAndCacheValueDeserializer(DeserializerCache.java:244)
    at com.fasterxml.jackson.databind.deser.DeserializerCache.findValueDeserializer(DeserializerCache.java:142)
    at com.fasterxml.jackson.databind.DeserializationContext.findNonContextualValueDeserializer(DeserializationContext.java:466)
    at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.resolve(BeanDeserializerBase.java:479)
    at com.fasterxml.jackson.databind.deser.DeserializerCache._createAndCache2(DeserializerCache.java:293)
    at com.fasterxml.jackson.databind.deser.DeserializerCache._createAndCacheValueDeserializer(DeserializerCache.java:244)
    at com.fasterxml.jackson.databind.deser.DeserializerCache.findValueDeserializer(DeserializerCache.java:142)
    at com.fasterxml.jackson.databind.DeserializationContext.findContextualValueDeserializer(DeserializationContext.java:443)
    at com.fasterxml.jackson.datatype.guava.deser.GuavaCollectionDeserializer.createContextual(GuavaCollectionDeserializer.java:67)
    at com.fasterxml.jackson.databind.DeserializationContext.handlePrimaryContextualization(DeserializationContext.java:650)
    at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.resolve(BeanDeserializerBase.java:490)
    at com.fasterxml.jackson.databind.deser.DeserializerCache._createAndCache2(DeserializerCache.java:293)
    at com.fasterxml.jackson.databind.deser.DeserializerCache._createAndCacheValueDeserializer(DeserializerCache.java:244)
    at com.fasterxml.jackson.databind.deser.DeserializerCache.hasValueDeserializerFor(DeserializerCache.java:191)
    at com.fasterxml.jackson.databind.DeserializationContext.hasValueDeserializerFor(DeserializationContext.java:421)
    at com.fasterxml.jackson.databind.ObjectMapper.canDeserialize(ObjectMapper.java:2729)
    at org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.canRead(AbstractJackson2HttpMessageConverter.java:159)
    at org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.canRead(AbstractJackson2HttpMessageConverter.java:149)
cowtowncoder commented 6 years ago

You have library version incompatibility somewhere: probably older (minor version of) jackson-databind and newer (minor version of) jackson-datatype-jsr310. While patch versions need not match (although it is preferable they do), minor versions must match in that version being depended on is not lower (that is, minor version of jackson-databind has to be at least that of datatype libraries). Some mismatched version do work but not all.

marcosscriven commented 6 years ago

Thanks @cowtowncoder - you are correct. It seems jackson-core was being downgraded by importing the spring boot dependencies pom http://central.maven.org/maven2/org/springframework/boot/spring-boot-dependencies/1.5.7.RELEASE/spring-boot-dependencies-1.5.7.RELEASE.pom

cowtowncoder commented 6 years ago

@marcosscriven Ok good that you were able to figure this out -- such problems are sometimes tricky to solve.