Aminul
Aminul

Reputation: 1738

jackson.databind no such method errors

I'm using auth0-java client library to interact with auth0 v2 service, my codes compile and works fine at my development environment but when I deploy that build in another test environment it throws the following exception:

java.lang.NoSuchMethodError:com.fasterxml.jackson.databind.ObjectMapper.readerFor(Lcom/fasterxml/jackson/databind/JavaType;)Lcom/fasterxml/jackson/databind/ObjectReader;
    at com.auth0.json.mgmt.users.UsersPageDeserializer.getArrayElements(UsersPageDeserializer.java:52)
    at com.auth0.json.mgmt.users.UsersPageDeserializer.deserialize(UsersPageDeserializer.java:30)
    at com.auth0.json.mgmt.users.UsersPageDeserializer.deserialize(UsersPageDeserializer.java:15)
    at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:3562)
    at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:2597)
    at com.auth0.net.CustomRequest.parseResponse(CustomRequest.java:63)
    at com.auth0.net.BaseRequest.execute(BaseRequest.java:37)
    at com.myapp.security.Auth0Service.getUserByEmail(Auth0Service.java:246)
    at com.myapp.security.Auth0Service.checkForExsistingAuth0Account(Auth0Service.java:266)
    at com.myapp.security.AdminUILayout.lambda$launchProgressUpdater$0(AdminUILayout.java:293)
at java.lang.Thread.run(Thread.java:745)

I've already gone through several stackover flow questions like this and tried by cleaning .m2/repository/com/fasterxml folder of that test environment, but cloudn't solve the no such method error here is my pom file and related codes are given below:

code

public User getUserByEmail(String email){
        UserFilter filter = new UserFilter();
        filter.withQuery(email);
        Request<UsersPage> request = mgmt.users().list(filter);
        try {
            UsersPage response = request.execute();
            for (User u:response.getItems()) {
                if (u.getEmail().equals(email)) {
                    return u;
                }
            }
        } catch (APIException exception) {
            // api error
            System.out.println("APIException:::::"+exception.getDescription());
        } catch (Auth0Exception exception) {
            // request error
             System.out.println("Auth0Exception:::::"+exception.getMessage());
        }catch(Exception ex){
            System.out.println("Other exception:::::"+ex.getMessage());
        }
        return null;
    }

pom.xml

<properties>
    <jackson.version>2.8.5</jackson.version>
  </properties>
        <dependency>
            <groupId>com.fasterxml.jackson.dataformat</groupId>
            <artifactId>jackson-dataformat-yaml</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.auth0</groupId>
        <artifactId>auth0</artifactId>
        <version>1.0.0</version>
    </dependency>

Update I've moved those jackson dependencies into <dependencyManagement> section of my pom.xml file,

<dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>com.fasterxml.jackson.core</groupId>
                <artifactId>jackson-core</artifactId>
                <version>2.8.5</version>
            </dependency>
            <dependency>
                <groupId>com.fasterxml.jackson.core</groupId>
                <artifactId>jackson-databind</artifactId>
                <version>2.8.5</version>
            </dependency>
            <dependency>
                <groupId>com.fasterxml.jackson.core</groupId>
                <artifactId>jackson-annotations</artifactId>
                <version>2.8.0</version>
            </dependency>
        </dependencies>
    </dependencyManagement>

according to maven documentation ,no matter which version of library jackson-core is requested by a dependency, version ${jackson.version} will always be used, still my codes works in local ,but in that test server the the exception remains same, even if I deploy my war file in that test server code throws the same exception.

Upvotes: 7

Views: 20647

Answers (6)

user9960178
user9960178

Reputation: 1

<!-- faster JSON -->
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>2.12.0</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-annotations</artifactId>
            <version>2.12.0</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-core</artifactId>
            <version>2.12.0</version>
        </dependency>

Upvotes: -2

user3437460
user3437460

Reputation: 17474

For me, I encountered the same exception due to lower version of jackson-databind:

From:

<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-databind</artifactId>
    <version>2.5.0</version>
</dependency>

Changed to:

<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-databind</artifactId>
    <version>2.8.9</version>
</dependency>

I just update my pom.xml file with higher version of jackson-databind. Then right-click Project --> Update Maven Project and the exception is resolved.

Upvotes: 0

Aminul
Aminul

Reputation: 1738

finally solved the issue , I found that glassfish 4.1.1 has a very old version 2.3.2 of jackson-core jackson-annotation and jackson-databind, so we decided to use Payara server that uses fairly latest version of jackson jackson 2.8.5 and tested the no such method error is solved, the code works fine in that Payara server

Update: glassfish version 5.0 uses updated version jackson 2.8.9 , I think using that will solve this issue too

Upvotes: 3

seakale
seakale

Reputation: 11

Please check version.

Screenshot:
Versions screenshot

Upvotes: 1

Nikolai  Shevchenko
Nikolai Shevchenko

Reputation: 7521

Probably one of your other artifacts depends on different version of databind. You can try to exlude it explicitly from each of them to guess

<dependency>
  ...
  <exclusions>
    <exclusion>
      <groupId>com.fasterxml.jackson.core</groupId>
      <artifactId>jackson-databind</artifactId>
    </exclusion>
  </exclusions> 
</dependency>

Upvotes: 1

Suren Aznauryan
Suren Aznauryan

Reputation: 1094

most likely you have compiled your code against a different version of the class, than the one you are using when running it.

Please make sure that on the environment where you run the code there is no any other version of jackson-databind dependency on your classpath.

Upvotes: 4

Related Questions