7

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.

lax1089
  • 3,403
  • 3
  • 17
  • 37
Aminul
  • 1,738
  • 2
  • 24
  • 42
  • What test server and version are you using? – Martijn Burger May 21 '17 at 21:40
  • here is my test server configs : Ubuntu 16.04.1 LTS (GNU/Linux 4.4.0-47-generic x86_64) , Glassfish 4.1.1 and openjdk 9 – Aminul May 22 '17 at 09:17
  • Well, I am using WildFly most of the time. But I can find a lot of articles about jackson and glassfish 4 issues http://blog.mikeski.net/blog_post/449 – Martijn Burger May 22 '17 at 11:38
  • @MartijnBurger yes, we are moving from glassfish too and planning to use [Payara](http://www.payara.fish/) from now on , that test server will also be updated , I'll update this question if the issue solves after using Payara – Aminul May 22 '17 at 11:57

6 Answers6

4

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.

Suren Aznauryan
  • 984
  • 10
  • 24
  • Thanks for your suggestion, I'm checking the entire dependency graph to exclude any other older version – Aminul May 04 '17 at 13:50
  • 1
    I think in the pom dependency graph you will not have any problem, because if execution of `mvn clean install` succeeds the maven compile phase then that means that even if there are transitive dependencies the dependency resolution has chosen the right version where the needed method exists and put that version into the built artifact. I think the problem is in the environment where you try to run the built artifact, possibly in classpath there is also another version of the same jar. – Suren Aznauryan May 04 '17 at 14:11
3

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

Aminul
  • 1,738
  • 2
  • 24
  • 42
  • @thanhdung0312 Use`glassfish` version `5.0` , that uses updated version `jackson 2.8.9` , I think upding glassfish will solve your issue https://github.com/javaee/glassfish/releases/tag/5.0-b23 – Aminul Nov 14 '18 at 13:37
1

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>
Nikolai Shevchenko
  • 7,083
  • 8
  • 33
  • 42
1

Please check version.

Screenshot:
Versions screenshot

Jon Saw
  • 7,599
  • 6
  • 48
  • 57
seakale
  • 11
  • 2
0

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.

user3437460
  • 17,253
  • 15
  • 58
  • 106
-2
<!-- 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>
  • The issue is already solved and we found the reason behind the problem https://stackoverflow.com/a/44201736/1298308 , anyway welcome to stackoverflow – Aminul Dec 11 '20 at 05:04