How to exclude jackson library without excluding resteasy in JBoss EAP 7.1

I want to use my custom Jackson version in JBOSS. For that I want to exclude native jboss jackson library and add my version as gradle dependency. I also use resteasy in the project and don't wanna exclude jax-rs module. Is it possible? Tried configure

jboss-deployment-structure.xml

but it doesn't help:

<jboss-deployment-structure>
    <deployment>
        <exclusions>
            <module name="com.fasterxml.jackson.core.jackson-core" />
            <module name="com.fasterxml.jackson.core.jackson-annotations" />
            <module name="com.fasterxml.jackson.core.jackson-databind" />
            <module name="com.fasterxml.jackson.datatype.jackson-datatype-jdk8" />
            <module name="com.fasterxml.jackson.datatype.jackson-datatype-jsr310" />
            <module name="com.fasterxml.jackson.jaxrs.jackson-jaxrs-json-provider" />
            <module name="org.jboss.resteasy.resteasy-jackson2-provider" />
            <module name="org.jboss.resteasy.resteasy-jackson-provider" />

            <module name="com.fasterxml.jackson.core.databind"/>
        </exclusions>
    </deployment>
</jboss-deployment-structure>

objectMapper.getClass().getPackage().getImplementationVersion()

always terurns

2.8.9.redhat-1

Upvotes: 0

Views: 2370

Answers (1)

areus
areus

Reputation: 2947

The problem is that jackson library is a dependency of the org.jboss.resteasy.resteasy-jackson2-provider module. And that module is an automatic dependency of any WAR subdeployment of your EAR that uses JAX-RS annotations (See Table 3.1. Implicit Module Dependencies of the Redhat 7.2 Development Guide).

You need to exclude the resteasy-jackson2-provider module but at the subdeployment level of your WAR using JAX-RS, and redefine it to exclude all the jackson dependencies. You can see this aproach with a similar case (modules included by automatic dependencies) https://developer.jboss.org/thread/175075

I've tested this on JBoss 7.2.6

<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.2">

    <sub-deployment name="myrestmodule.war">
        <dependencies>
            <module name="deployment.org.jboss.resteasy.resteasy-jackson2-provider" />
        </dependencies>
        <exclusions>
            <module name="org.jboss.resteasy.resteasy-jackson2-provider" />
        </exclusions>
    </sub-deployment>

    <module name="deployment.org.jboss.resteasy.resteasy-jackson2-provider">
        <dependencies>
            <module name="org.jboss.resteasy.resteasy-jackson2-provider" export="true">
                <imports>
                    <exclude path="com/fasterxml/jackson/**" />
                </imports>
            </module>
        </dependencies>
    </module>

</jboss-deployment-structure>

The required jackson libs must be included on myrestmodule.war WEB-INF/lib folder.

UPDATED

This aproach doesn't work if jackson is used in other libraries of the EAR and not only on the WAR using JAX-RS. For example, if a bean in JAR in the library directory of the EAR is used on the WAR, jackson won't recognize the annotations in it.

For this deployment to work, the exclusion of the "org.jboss.resteasy.resteasy-jackson2-provider" module needs to be done at the EAR deployment level, and the jackson libraries need to be included in the library directory of the EAR instead of the WEB-INF/lib of the WAR.

This would be the updated jboss-deployment-structure.xml on the META-INF directory of the EAR:

<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.2">
    <deployment>
        <dependencies>
            <module name="deployment.org.jboss.resteasy.resteasy-jackson2-provider" />
        </dependencies>
        <exclusions>
            <module name="org.jboss.resteasy.resteasy-jackson2-provider" />
        </exclusions>
    </deployment>

    <sub-deployment name="myrestmodule.war">
        <dependencies>
            <module name="deployment.org.jboss.resteasy.resteasy-jackson2-provider" />
        </dependencies>
        <exclusions>
            <module name="org.jboss.resteasy.resteasy-jackson2-provider" />
        </exclusions>
    </sub-deployment>

    <module name="deployment.org.jboss.resteasy.resteasy-jackson2-provider">
        <dependencies>
            <module name="org.jboss.resteasy.resteasy-jackson2-provider" export="true">
                <imports>
                    <exclude path="com/fasterxml/jackson/**" />
                </imports>
            </module>
        </dependencies>
    </module>
</jboss-deployment-structure>

Upvotes: 2

Related Questions