using Jackson annotations in Wildfly

会有一股神秘感。 提交于 2019-12-22 10:49:41

问题


I'm struggling to get Jackson Annotations to work in my project which is deployed in wildfly.

I already tried implementing a MessageBodyWriter but no success. My project looks like this: I have an ear with an ejb module which holds the annotated Pojos and I have a web module with the REST services. This is my current configuration / dependencies:

ejb-module pom.xml:

<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-annotations</artifactId>
    <version>2.2.3</version>
    <scope>provided</scope>
    <type>jar</type>
</dependency>

rest-module pom.xml:

no jackson dependencies.

ear-project pom.xml:

<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-annotations</artifactId>
    <version>2.2.3</version>
</dependency>
<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-core</artifactId>
    <version>2.2.3</version>
</dependency>
<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-databind</artifactId>
    <version>2.2.3</version>
</dependency>
<dependency>
    <groupId>org.jboss.resteasy</groupId>
    <artifactId>resteasy-jackson2-provider</artifactId>
    <version>3.0.6.Final</version>
</dependency>

ear-project /META-INF/jboss-deployment-structure.xml:

<jboss-deployment-structure>
    <deployment>
        <exclusions>
           <module name="org.jboss.resteasy.resteasy-jackson-provider"/>
        </exclusions>
        <dependencies>
            <module name="org.jboss.resteasy.resteasy-jackson2-provider" services="import"/>
        </dependencies>
    </deployment>
</jboss-deployment-structure> 

but the jackson annotations are ignored. What am I missing? or did I do too much?


回答1:


The RESTEasy and Jackson dependencies should be marked as <scope>provided</scope>.

Also if you're only using JAX-RS and Jackson in your WAR, just move jboss-deployment-structure.xml to your WAR/WEB-INF directory. If you don't want to move it you might need to add a <sub-deployment/>.

<jboss-deployment-structure>
    <sub-deployment name="rest-module.war">
        <exclusions>
           <module name="org.jboss.resteasy.resteasy-jackson-provider"/>
        </exclusions>
        <dependencies>
            <module name="org.jboss.resteasy.resteasy-jackson2-provider" services="import"/>
        </dependencies>
    </sub-deployment>
</jboss-deployment-structure> 


来源:https://stackoverflow.com/questions/22442134/using-jackson-annotations-in-wildfly

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!