Kafka Json consumer error java.lang.NoSuchFieldError: READ_UNKNOWN_ENUM_VALUES_USING_DEFAULT_VALUE
Asked Answered
S

3

14

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?

Smoulder answered 15/5, 2023 at 19:43 Comment(1)
Use com.fasterxml.jackson.core:jackson-annotations:2.15.0Darling
O
14

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.

Ode answered 7/7, 2023 at 16:48 Comment(1)
jackson-annotations alone didn't help me, it threw another error, I had to add com.fasterxml.jackson.core:jackson-core too.Divisibility
L
5

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,
Lepine answered 15/5, 2023 at 19:56 Comment(0)
C
5

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

Cantwell answered 1/11, 2023 at 11:33 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.