Object Mapper - YAMLFactory - exception due to missing _createContentReference method
Asked Answered
M

4

11

I'm using the latest 2.13.0 version of jackson, and when I try to parse a YAML file, I'm getting this exception

 java.lang.NoSuchMethodError: 'com.fasterxml.jackson.core.io.ContentReference com.fasterxml.jackson.dataformat.yaml.YAMLFactory._createContentReference(java.lang.Object)'

What could be the issue?

The dependencies that I've included are jackson-core, jackson-databind and jackson-dataformat-yaml - all 2.13.0

Meyeroff answered 20/12, 2021 at 12:48 Comment(0)
T
15

No such method error in most cases means that you have have 2 dependencies that are the same but with different versions, however the application is loading the version that does not have this method in it,

The reference to this _createContentReference exists in YAMLFactory in jackson-dataformat-yaml.jar

The actual _createContentReference implementation exists in com.fasterxml.jackson.core.JsonFactory which exists jackson-core.2.13.0.

In your case, you probably have another jackson-core.jar with an older version as part of your indirect dependencies.

You can see mvn dependency:tree or your IDE (Such as Eclipse allows you to search for dependency by name, and it returns all that match, including their versions)

Thorax answered 20/12, 2021 at 12:57 Comment(0)
F
3

Thanks. It helped me to exclude jackson-dataformat-yaml version 2.13.1 from quarkus-smallrye-openapi and include 2.12.3 . Like this :

    <dependency>
        <groupId>io.quarkus</groupId>
        <artifactId>quarkus-smallrye-openapi</artifactId>
        <exclusions>
            <exclusion>
                <groupId>com.fasterxml.jackson.dataformat</groupId>
                <artifactId>jackson-dataformat-yaml</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

    <dependency>
        <groupId>com.fasterxml.jackson.dataformat</groupId>
        <artifactId>jackson-dataformat-yaml</artifactId>
        <version>2.12.3</version>
    </dependency>
Fredel answered 14/2, 2022 at 15:57 Comment(2)
version of quarkus?Leaflet
I'm using quarkus version 2.7.1.FinalFredel
T
1

Ran into the same problem with spring boot 3, gradle and org.openapi.generator plugin 7.3.0. Problem was caused by the openapi plugin using an ancient version of jackson-core (2.12.x) under the hood for any reason, despite its pom says jackson-core 2.15.3 and my project definitely uses the same version.

The following entry (in the root build.gradle) forces the plugin to use the newer version and worked for me:

buildscript {
  dependencies {
    classpath 'com.fasterxml.jackson.core:jackson-core:2.15.3'
  }
}
Tager answered 16/2, 2024 at 18:22 Comment(0)
M
0

The same problem I also faced. My environment is - Wildfly version - 26.1.1-Final Spring boot - 2.7.8

The issue is coming because Wildfly has the same version API already added as module and the same set of jackson* series jars are going thourgh spring boot hence on runtime it is creating issue.

Solution - all jackson* jar under spring-boot pom.xml add into exclusion list and separtly added dependencies with scope provied. My modified pom.xml is as below -

<properties>
    <spring.boot.version>2.7.8</spring.boot.version>
    <jackson.version>2.13.4</jackson.version>       
</properties>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
        <exclusions>
            <exclusion>
                <groupId>ch.qos.logback</groupId>
                <artifactId>logback-classic</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-tomcat</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.apache.logging.log4j</groupId>
                <artifactId>log4j-to-slf4j</artifactId>
            </exclusion>

            <exclusion>
                <artifactId>jackson-databind</artifactId>
                <groupId>com.fasterxml.jackson.core</groupId>
            </exclusion>
           <!-- Exclusion list -->
            <exclusion>
                <artifactId>jackson-datatype-jdk8</artifactId>
                <groupId>com.fasterxml.jackson.datatype</groupId>
            </exclusion>
            <exclusion>
                <artifactId>jackson-datatype-jsr310</artifactId>
                <groupId>com.fasterxml.jackson.datatype</groupId>
            </exclusion>
            <exclusion>
                <artifactId>jackson-core</artifactId>
                <groupId>com.fasterxml.jackson.core</groupId>
            </exclusion>
        </exclusions>
    </dependency>

    <!-- added dependency with provided scope -->
    <dependency>
        <artifactId>jackson-databind</artifactId>
        <groupId>com.fasterxml.jackson.core</groupId>
        <version>${jackson.version}</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <artifactId>jackson-datatype-jdk8</artifactId>
        <groupId>com.fasterxml.jackson.datatype</groupId>
        <version>${jackson.version}</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <artifactId>jackson-datatype-jsr310</artifactId>
        <groupId>com.fasterxml.jackson.datatype</groupId>
        <version>${jackson.version}</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <artifactId>jackson-core</artifactId>
        <groupId>com.fasterxml.jackson.core</groupId>
        <version>${jackson.version}</version>
        <scope>provided</scope>
    </dependency>
</dependencies>
Multivalent answered 5/2, 2023 at 15:20 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.