简体   繁体   中英

Difference serializing POJO using RestEasy when deployed with JBoss AS 7 and Jetty

Deploying my application on JBoss AS 7 and then Jetty, I noticed an undesirable difference when RestEasy serialized my POJO. With Jetty, I have the following JSON:

{
"pojo-name":{
    "lines":[
        {
            "code":"250-1",
            "id":1143,
         }]
    }
}

However, when deployed on JBoss AS 7, the "pojo-name" given by the @XmlRootElement annotation simply disappear resulting:

{
"lines":[
    {
        "code":"250-1",
        "id":1143,
    }]
}

I have a POM file with the following dependencies:

  <dependency>
      <groupId>org.jboss.resteasy</groupId>
      <artifactId>resteasy-jaxrs</artifactId>
      <version>${resteasy.version}</version>
      <scope>provided</scope>
  </dependency>
  <dependency>
      <groupId>org.jboss.resteasy</groupId>
      <artifactId>resteasy-jaxb-provider</artifactId>
      <version>${resteasy.version}</version>
      <scope>provided</scope>
  </dependency>
  <dependency>
      <groupId>org.jboss.resteasy</groupId>
      <artifactId>jaxrs-api</artifactId>
      <version>${resteasy.version}</version>
      <scope>provided</scope>
  </dependency>
  <dependency>
      <groupId>org.jboss.resteasy</groupId>
      <artifactId>resteasy-spring</artifactId>
      <version>${resteasy.version}</version>
      <exclusions>
          <exclusion>
              <artifactId>commons-logging</artifactId>
              <groupId>commons-logging</groupId>
          </exclusion>
          <exclusion>
              <artifactId>jaxb-impl</artifactId>
              <groupId>com.sun.xml.bind</groupId>
          </exclusion>
          <exclusion>
              <artifactId>sjsxp</artifactId>
              <groupId>com.sun.xml.stream</groupId>
           </exclusion>
           <exclusion>
              <artifactId>jsr250-api</artifactId>
              <groupId>javax.annotation</groupId>
           </exclusion>
           <exclusion>
              <artifactId>activation</artifactId>
              <groupId>javax.activation</groupId>
           </exclusion>
      </exclusions>
 </dependency>

My POJO class looks like this:

@XmlRootElement(name = "pojo-name")
public class LinesResponse implements Serializable {

    private static final long serialVersionUID = -8717658630497030320L;

    private List<Lines> lines;

    public LinesResponse() {}

    // Getters and setters
}

Your help would be highly appreciated! Thank you guys.


EDIT:

It seems that I'm facing a possible conflict between JAXB providers. Maybe when my app is deployed using Jetty I'm getting Jettison as a JAXB provider and when deployed on JBoss Jackson. From JBoss documentation we have:

If your Jackson classes are annotated with JAXB annotations and you have the resteasy-jaxb-provider in your classpath, you may trigger the Jettision JAXB marshalling code. To turn off the JAXB json marshaller use the @org.jboss.resteasy.annotations.providers.jaxb.IgnoreMediaTypes("application/*+json") on your classes.

As soon as I get home, I will try this approach to be sure.

Just confirmed the assumptions descried above. It was a conflit between JAXB providers. When deployed on JBoss my app was using Jackson and on Jetty it was using Jettison. In order to the problem, I forced the use of Jackson provider with

   <dependency>
        <groupId>org.jboss.resteasy</groupId>
        <artifactId>resteasy-jackson-provider</artifactId>
        <version>${resteasy.version}</version>
        <scope>provided</scope>
   </dependency>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM