NoSuchMethodError:com.fasterxml.jackson.databind.ObjectMapper.readFor(..)

时间:2017-11-29 18:51:00

标签: jackson fasterxml

我正在使用以下的fastxml依赖项,但仍面临以下错误:

java.lang.NoSuchMethodError:com.fasterxml.jackson.databind.ObjectMapper.readerFor(Ljava / lang / Class;)Lcom / fasterxml / jackson / databind / ObjectReader;

    ObjectMapper instance = new ObjectMapper();
    instance.readerFor(UserM.class);

Dependencies:
     <jackson.version>2.8.8</jackson.version>
     <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-core</artifactId>
        <version>${jackson.version}</version>
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-databind</artifactId>
        <version>${jackson.version}</version>
    </dependency>           
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-annotations</artifactId>
        <version>${jackson.version}</version>
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.dataformat</groupId>
        <artifactId>jackson-dataformat-xml</artifactId>
        <version>${jackson.version}</version>
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.datatype</groupId>
        <artifactId>jackson-datatype-joda</artifactId>
        <version>${jackson.version}</version>
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.module</groupId>
        <artifactId>jackson-module-jaxb-annotations</artifactId>
        <version>${jackson.version}</version>
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.jaxrs</groupId>
        <artifactId>jackson-jaxrs-json-provider</artifactId>
        <version>${jackson.version}</version>
    </dependency>

1 个答案:

答案 0 :(得分:1)

ObjectMapper readFor 方法是在 2.6 版本中引入的。 您的运行时可能使用旧版本的库。如果您使用的是 eclipse,您可以在引用的库下检查您使用的版本。

enter image description here