Reputation: 151
I'm using spring boot to run kafka consumer with Json Deserializer. When running the application I'm getting the error
Caused by: java.lang.NoSuchFieldError: READ_UNKNOWN_ENUM_VALUES_USING_DEFAULT_VALUE
at com.fasterxml.jackson.databind.deser.std.EnumDeserializer.createContextual(EnumDeserializer.java:211)
at com.fasterxml.jackson.databind.DeserializationContext.handlePrimaryContextualization(DeserializationContext.java:836)
at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.resolve(BeanDeserializerBase.java:550)
at com.fasterxml.jackson.databind.deser.DeserializerCache._createAndCache2(DeserializerCache.java:294)
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:644)
at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.resolve(BeanDeserializerBase.java:539)
at com.fasterxml.jackson.databind.deser.DeserializerCache._createAndCache2(DeserializerCache.java:294)
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:644)
at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.resolve(BeanDeserializerBase.java:539)
at com.fasterxml.jackson.databind.deser.DeserializerCache._createAndCache2(DeserializerCache.java:294)
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.findRootValueDeserializer(DeserializationContext.java:654)
at com.fasterxml.jackson.databind.ObjectReader._prefetchRootDeserializer(ObjectReader.java:2430)
at com.fasterxml.jackson.databind.ObjectReader.<init>(ObjectReader.java:194)
at com.fasterxml.jackson.databind.ObjectMapper._newReader(ObjectMapper.java:780)
at com.fasterxml.jackson.databind.ObjectMapper.readerFor(ObjectMapper.java:4263)
at org.springframework.kafka.support.serializer.JsonDeserializer.initialize(JsonDeserializer.java:502)
at org.springframework.kafka.support.serializer.JsonDeserializer.setupTarget(JsonDeserializer.java:487)
... 56 common frames omitted
I'm using spring-boot 3.0.5 and jackson-databing 2.15.0. Has anyone faced with the same error?
I have tried to debug the problem and it seems to be realted to the fact that my domain object contains Enum type as a property. Jackson scans the structure of the object and eagerly loads deserializer for each type, it fails when reaches the enum type. Does anyone have an idea how I could track and solve the problem?
Upvotes: 15
Views: 13181
Reputation: 1
I also had the same error, resolved it by adding one library for 'jackson-annotations' which was missing earlier. So there should be 3 jackson libraries with the same version i.e jackson-core, jackson-annotations and jackson-databind.
Upvotes: 0
Reputation: 619
I had the same issue and getting the same error when I used jackson-databind to serialize and deserialize java enum and it seesm that all 2.15.x have the same issue . the only way to gid rid of this is to return to any 2.14. version For example the issue gone when I downgraded the vesrion to be as follow
<properties>
<java.version>17</java.version>
<jackson-databind.version>2.14.3</jackson-databind.version>
</properties>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson-databind.version}</version>
</dependency>
Also , it seems that reported https://github.com/FasterXML/jackson-databind/issues/3637 is something related
Upvotes: 5
Reputation: 7744
Looks like it was released in 2.15.0
going by this thread on github.
Adding this 'com.fasterxml.jackson.core:jackson-annotations:2.15.0'
to dependencies fixes it. Credit to @Wenod for pointing it out.
Upvotes: 16
Reputation: 174484
java.lang.NoSuchFieldError: READ_UNKNOWN_ENUM_VALUES_USING_DEFAULT_VALUE
It looks like you, somehow, have an older version of jackson-annotations jar on the class path; it should be the same version as the databind jar.
That is a new enum value in JsonFormat.Feature
:
/**
* Override for <code>DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_USING_DEFAULT_VALUE</code>,
* which allows unknown Enum values to be ignored and a predefined value specified through
* {@link com.fasterxml.jackson.annotation.JsonEnumDefaultValue @JsonEnumDefaultValue} annotation.
*
* @since 2.15
*/
READ_UNKNOWN_ENUM_VALUES_USING_DEFAULT_VALUE,
Upvotes: 6