1

I'm trying to use my objects with JAXB annotations for application/json output with my JAX-RS resource. I'm running on JBoss AS7 with RestEasy (both lastest versions - 7.1.1.Final and 2.3.4.Final). The issue is that I would like to customize my JSON output. I must note that I don't care if I will use Jettison or Jackson, but I was able only make Jettison work (deploy application) without errors. I also would like to stick only with JAXB annotations on my objects if possible - but it is not necessairly needed.

1) I want to omit "@" within XmlAttribute annotated fields. I found out property how to do it with Jettison, but I don't know how to configure it on JBoss AS7. Didn't find any ContextResolver example.

2) I would like to have "normal" JSON arrays, e.g.

@XmlRootElement(name = "root")
@XmlAccessorType(XmlAccessType.FIELD)
public class Root {

    @XmlElementRef(type = Entry.class, required = false)
    // no difference with @XmlElement
    private Set<Entry> entries;
}

serializes into

{"entries":
  {"entry":[{...},{...},{...}]}
}

and I would expect

{"entries":
  [
   {"entry":{...}},
   {"entry":{...}},
   {"entry":{...}}      
  ]
}

or just (omit XmlRootElement)

{"entries":
 [{...},{...},{...}]
}

3) As I noted, I don't care what provider (Jettison/Jackson) will I use but it is hard to find working example how to correctly set maven dependencies for application to be deployable without errors. So far I'm using:

    <dependency>
        <groupId>org.jboss.resteasy</groupId>
        <artifactId>resteasy-jaxrs</artifactId>
        <version>${resteasyVersion}</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>org.jboss.resteasy</groupId>
        <artifactId>resteasy-jaxb-provider</artifactId>
        <version>${resteasyVersion}</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>org.jboss.resteasy</groupId>
        <artifactId>resteasy-jettison-provider</artifactId>
        <version>${resteasyVersion}</version>
        <!--<scope>provided</scope>-->
        <exclusions>
            <exclusion>
                <groupId>javax.xml.bind</groupId>
                <artifactId>jaxb-api</artifactId>
            </exclusion>
            <exclusion>
                <groupId>com.sun.xml.bind</groupId>
                <artifactId>jaxb-impl</artifactId>
            </exclusion>
            <exclusion>
                <groupId>javax.xml.stream</groupId>
                <artifactId>stax-api</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

Thanks for all answers

zdenda.online
  • 2,451
  • 3
  • 23
  • 45
  • People say to use Jackson, but 1: it is unclear which one Jboss 7.1 uses by default 2: just adding the dependencies for Jackson gives me errors, so I can never get to the easier part which is writing the ContextResolver. It seems hard to configure Jettison and judging by Google searches, Jettison is not as popular and certainly has less documentation and tutorials. – user798719 Jun 02 '13 at 17:50

1 Answers1

0

So far I managed to make Jackson working and use its provider-specific annotations (@JsonProperty ... and so) which solved my problem. I tried to find only JAXB solution but I can accept also this.

Btw my dependencies

    <dependency>
        <groupId>org.jboss.resteasy</groupId>
        <artifactId>resteasy-jaxrs</artifactId>
        <version>${resteasyVersion}</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>org.jboss.resteasy</groupId>
        <artifactId>resteasy-jaxb-provider</artifactId>
        <version>${resteasyVersion}</version>
    </dependency>
    <dependency>
        <groupId>org.jboss.resteasy</groupId>
        <artifactId>resteasy-jackson-provider</artifactId>
        <version>${resteasyVersion}</version>
    </dependency>
zdenda.online
  • 2,451
  • 3
  • 23
  • 45