Set JSON provider at RESTEasy on JBoss 7.1.1

前端 未结 4 1265
执念已碎
执念已碎 2021-02-15 17:26

How could I set JSON provider for RestEasy at JBoss 7.1.1?

RestEasy documentation says:

RESTEasy allows you to marshall JAXB annotated POJOs to an

相关标签:
4条回答
  • 2021-02-15 17:58

    From what I observed right now, Jackson is the default in JBoss AS 7.1.2.

    First, the RestEasy modules are hidden from app's classloader, which IMO should not be. So I just filed https://issues.jboss.org/browse/AS7-5605 .

    Second, to your question: To set the particular provider, you need to remove it from classloader's spot in AS - so again, to go module.xml's and comment out those providers which you don't want to use - if Jackson is available, RestEasy uses it; otherwise it uses Jettison.

    Also, add them your project as a compile time dependency, so you can use their specific annotations. Example:

        <!-- RestEasy -->
        <dependency>
            <groupId>org.jboss.resteasy</groupId>
            <artifactId>jaxrs-api</artifactId>
            <version>2.3.4.Final</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.codehaus.jackson</groupId>
            <artifactId>jackson-core-asl</artifactId>
            <version>1.9.2</version>
            <scope>provided</scope>
        </dependency>
    

    Note: Until AS7-5605 is done, you need to set the versions manually. After (in later versions of AS), you have to remove these versions and use those defined in JBoss BOM. See JBoss AS QuckStarts for example.

    Feel free to create and contribute a QuickStart of RestEasy using alternative provider.

    0 讨论(0)
  • 2021-02-15 17:59

    As a follow-on to ahus1's answer: if you have a multi-level deployment archive (i.e. a top-level EAR file containing an EJB jar and a war file), you will need to configure the exclusion of org.jboss.resteasy.resteasy-jackson-provider on whichever sub-deployment contains the RESTEasy/JAX-RS components.

    In my deployment, for example, my REST endpoints were annotated on top of EJBs in my EJB jar file, while my @ApplicationPath-annotated javax.ws.rs.core.Application subclass which activates RESTEasy was in my war file. I found that the approaches of putting the exclusions solely on the top-level (EAR) deployment (as in ahus1's example) or on the EJB-jar-level deployment were ineffective, but I finally got RESTEasy to use Jettison rather than Jackson by putting the exclusions on all 3 levels (EAR, EJB, Web):

    <?xml version="1.0" encoding="UTF-8" ?>
    <jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.2">
        <deployment>
            <exclusions>
                <module name="org.jboss.resteasy.resteasy-jackson-provider" />
            </exclusions>
            <dependencies>
                <module name="org.jboss.resteasy.resteasy-jettison-provider" />
            </dependencies>
        </deployment>
        <sub-deployment name="MyApp-ejb.jar">
            <exclusions>
                <module name="org.jboss.resteasy.resteasy-jackson-provider" />
            </exclusions>
            <dependencies>
                <module name="org.jboss.resteasy.resteasy-jettison-provider" />
            </dependencies>
        </sub-deployment>
        <sub-deployment name="MyApp.war">
            <exclusions>
                <module name="org.jboss.resteasy.resteasy-jackson-provider" />
            </exclusions>
            <dependencies>
                <module name="org.jboss.resteasy.resteasy-jettison-provider" />
            </dependencies>
        </sub-deployment>
    </jboss-deployment-structure>
    

    It's very likely that I only needed the exclusions on the subdeployments, and putting it on the main EAR deployment is superfluous; I didn't try it that way, since for now putting it on all three seems to work perfectly well.

    0 讨论(0)
  • 2021-02-15 18:05

    I added this line to standalone.conf.bat/sh and it solved my problem.

    set "JAVA_OPTS=%JAVA_OPTS% -Dcom.sun.jersey.server.impl.cdi.lookupExtensionInBeanManager=true"

    0 讨论(0)
  • 2021-02-15 18:07

    if you just want to have a different module pulled than the standard, you can provide this in a jboss specific deployment descriptor.

    Read https://docs.jboss.org/author/display/AS71/Class+Loading+in+AS7 to learn the details, and read https://docs.jboss.org/author/display/AS7/Implicit+module+dependencies+for+deployments to learn what modules JBoss uses by default.

    To exchange the two providers, provide a META-INF/jboss-deployment-structure.xml with the following content below.

    This switched the provider for me.

    Br Alexander.

    <jboss-deployment-structure>
      <deployment>
        <exclusions>
          <module name="org.jboss.resteasy.resteasy-jackson-provider" />
        </exclusions>
        <dependencies>
          <module name="org.jboss.resteasy.resteasy-jettison-provider" />
        </dependencies>
      </deployment>
    </jboss-deployment-structure>
    
    0 讨论(0)
提交回复
热议问题