2

When I am parsing a LocalDate field using the Jackson JSR310 module under Wildfly, it fails with the following exception:

 java.lang.NoSuchMethodError: com.fasterxml.jackson.core.JsonParser.hasToken(Lcom/fasterxml/jackson/core/JsonToken;)Z

I am using the wildfly-javaee7-with-tools for dependency management. The interesting parts of my pom.xml:

<properties>
    <version.wildfly>10.0.0.Final</version.wildfly>
    <version.jackson>2.6.3</version.jackson>
</properties>

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.wildfly.bom</groupId>
            <artifactId>wildfly-javaee7-with-tools</artifactId>
            <version>${version.wildfly}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

<dependencies>
    <dependency>
        <groupId>org.jboss.resteasy</groupId>
        <artifactId>resteasy-jackson2-provider</artifactId>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.datatype</groupId>
        <artifactId>jackson-datatype-hibernate5</artifactId>
        <version>${version.jackson}</version>
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.datatype</groupId>
        <artifactId>jackson-datatype-jdk8</artifactId>
        <version>${version.jackson}</version>
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.datatype</groupId>
        <artifactId>jackson-datatype-jsr310</artifactId>
        <version>${version.jackson}</version>
    </dependency>
</dependencies>

And my provider:

@Provider
public class ObjectMapperProvider implements ContextResolver<ObjectMapper> {

    private final ObjectMapper objectMapper;

    public ObjectMapperProvider() {
        this.objectMapper = new ObjectMapper();
        objectMapper.registerModule(new Jdk8Module());
        objectMapper.registerModule(new JavaTimeModule());
        objectMapper.registerModule(new Hibernate5Module());
    }

    @Override
    public ObjectMapper getContext(Class<?> aClass) {
        return objectMapper;
    }

}

This obviously looks like a dependency conflict. This is however the output of mvn dependency:tree, and everything Jackson related seems to be on 2.6.3.

[INFO] +- javax:javaee-web-api:jar:7.0:provided
[INFO] +- org.jboss.resteasy:resteasy-jackson2-provider:jar:3.0.14.Final:provided
[INFO] |  +- com.fasterxml.jackson.core:jackson-core:jar:2.6.3:compile
[INFO] |  +- com.fasterxml.jackson.core:jackson-databind:jar:2.6.3:compile
[INFO] |  +- com.fasterxml.jackson.core:jackson-annotations:jar:2.6.3:compile
[INFO] |  \- com.fasterxml.jackson.jaxrs:jackson-jaxrs-json-prov ider:jar:2.6.3:provided
[INFO] |     +- com.fasterxml.jackson.jaxrs:jackson-jaxrs-base:jar:2.6.3:provided
[INFO] |     \- com.fasterxml.jackson.module:jackson-module-jaxb-annotations:jar:2.6.3:provided
[INFO] +- com.fasterxml.jackson.datatype:jackson-datatype-hibernate5:jar:2.6.3:compile
[INFO] +- com.fasterxml.jackson.datatype:jackson-datatype-jdk8:jar:2.6.3:compile
[INFO] +- com.fasterxml.jackson.datatype:jackson-datatype-jsr310:jar:2.6.3:compile

I am also running on a Wildfly 10.0.0.Final server, so I don't expect version mismatches between the 10.0.0.Final pom.xml and the actual dependencies provided on the server.

  • please see https://issues.jboss.org/browse/WFLY-5911 – Apostolos Jul 03 '16 at 19:38
  • I know Wildfly is on a relatively old version of Jackson. But all my Jackson dependencies are on `2.6.3`, so how is this issue related to my problem? – Jan-Willem Gmelig Meyling Jul 03 '16 at 19:39
  • well, 3.0.14 has 2.6.3 dependency but it is not present in wildfly 10. so since you define it as provided, they arent included in your war right? – Apostolos Jul 03 '16 at 19:46
  • Pretty sure Jackson 2.6.3 is provided with Wildfly, because the Hibernate extension works just fine, and I am also able to generate JSON results. But the JSR extention seems to miss a method from the core; which is strange, as it should be compiled against the same dependency version. – Jan-Willem Gmelig Meyling Jul 03 '16 at 19:50
  • check this folder and check the version. wildfly-10.0.0.Final\modules\system\layers\base\com\fasterxml\jackson\core\jackson-core\main. i'm pretty sure you need to specify the jackson-core 2.6.3 dependency on its own. give it a try and let me know – Apostolos Jul 03 '16 at 19:52
  • Aha, it is provided by default, but its on version `2.5.4` instead of `2.6.3`. Seems the version number in `wildfly-javaee7` for `10.0.0.Final` is a bit newer and my AS is not a clean `10.0.0.Final` release... Thanks for your answers! – Jan-Willem Gmelig Meyling Jul 03 '16 at 19:58
  • i'll post it as an answer in order to accept it (and upvote it if you want). thank you – Apostolos Jul 03 '16 at 20:00
  • The scope of the dependencies should also be `provided` since they're provided by the container. – James R. Perkins Jul 05 '16 at 15:46
  • Based on my pom xml, the scope is provided? – Jan-Willem Gmelig Meyling Jul 05 '16 at 16:57

1 Answers1

2

check this folder and check the version. wildfly-10.0.0.Final\modules\system\layers\base\com\fasterxml\jackson\core\jacks‌​on-core\main. i'm pretty sure you need to specify the jackson-core 2.6.3 dependency on its own since org.jboss.resteasy:resteasy-jackson2-provider:jar:3.0.14.Final is of scope provided and 2.6.3 is not present in wildfly 10.

Apostolos
  • 10,033
  • 5
  • 24
  • 39
  • It is weird that the pom import from the artefact maintained by Wildfly itself specifies a newer version than they actually ship with the AS under the same version though... Now, how do I update the version there, can two different versions live next to each other? – Jan-Willem Gmelig Meyling Jul 03 '16 at 20:05
  • you can specify it in your pom.xml and i think it will use the one inside your war file. it will override the old one. I think i had done the same with an older spring project of mine trying to test some resteasy stuff and had to use 2.6.3 version. i just found the version in the tmp folder with the deployments so pretty sure it worked that way! – Apostolos Jul 03 '16 at 20:07
  • I worked around the issue by switching to `2.5.4`. It seems that the `Hibernate5Module` is compatible with `2.5.4`, even though its compiled against `2.6.3`. I will switch to `2.6.4` when `10.1.0.Final` will be released. – Jan-Willem Gmelig Meyling Jul 03 '16 at 20:16